mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2026-02-04 10:06:13 +01:00
added throttler and crypto quantity
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 ',
|
||||
|
||||
Reference in New Issue
Block a user