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

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 ',