added throttler and crypto quantity

This commit is contained in:
Kevsl 2024-06-07 16:18:29 +02:00
parent 3c42d14f61
commit b7f765f488
7 changed files with 24 additions and 3 deletions

2
package-lock.json generated
View File

@ -17,7 +17,7 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.17",
"@nestjs/throttler": "^5.1.1",
"@nestjs/throttler": "^5.1.2",
"@prisma/client": "^5.8.1",
"@prisma/studio": "^0.497.0",
"@types/nodemailer": "^6.4.14",

View File

@ -28,7 +28,7 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.17",
"@nestjs/throttler": "^5.1.1",
"@nestjs/throttler": "^5.1.2",
"@prisma/client": "^5.8.1",
"@prisma/studio": "^0.497.0",
"@types/nodemailer": "^6.4.14",

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Crypto" ADD COLUMN "quantity" DOUBLE PRECISION NOT NULL DEFAULT 1000;

View File

@ -14,6 +14,7 @@ model Crypto {
name String @unique
value Float
image String
quantity Float @default(1000)
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
UserHasCrypto UserHasCrypto[]

View File

@ -10,6 +10,7 @@ import { CryptoModule } from './crypto/crypto.module';
import { TradeModule } from './trade/trade.module';
import { OfferModule } from './offer/offer.module';
import { UserModule } from './user/user.module';
import { ThrottlerModule } from '@nestjs/throttler';
@Module({
imports: [
@ -24,6 +25,12 @@ import { UserModule } from './user/user.module';
TradeModule,
OfferModule,
UserModule,
ThrottlerModule.forRoot([
{
ttl: 60000,
limit: 40,
},
]),
],
controllers: [AppController],
providers: [AppService],

View File

@ -57,6 +57,7 @@ export class CryptoService {
name: dto.name,
image: dto.image,
value: dto.value,
quantity: dto.quantity,
},
});
@ -75,7 +76,9 @@ export class CryptoService {
id: userId,
},
});
if (crypto.quantity < dto.amount) {
throw new ForbiddenException('No more tokens available');
}
const necessaryAmount = crypto.value * dto.amount;
console.log(necessaryAmount, user.dollarAvailables);

View File

@ -17,6 +17,14 @@ export class CryptoDto {
@IsNumber()
value: number;
@ApiProperty({
type: Number,
description: 'Quantity of tokens available on the platform',
example: 100,
})
@IsNumber()
quantity: number;
@ApiProperty({
type: String,
description: 'Image for the cryptocurrency in ',