mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 06:00:12 +02:00
added throttler and crypto quantity
This commit is contained in:
parent
3c42d14f61
commit
b7f765f488
2
package-lock.json
generated
2
package-lock.json
generated
@ -17,7 +17,7 @@
|
|||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@nestjs/swagger": "^7.1.17",
|
"@nestjs/swagger": "^7.1.17",
|
||||||
"@nestjs/throttler": "^5.1.1",
|
"@nestjs/throttler": "^5.1.2",
|
||||||
"@prisma/client": "^5.8.1",
|
"@prisma/client": "^5.8.1",
|
||||||
"@prisma/studio": "^0.497.0",
|
"@prisma/studio": "^0.497.0",
|
||||||
"@types/nodemailer": "^6.4.14",
|
"@types/nodemailer": "^6.4.14",
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@nestjs/swagger": "^7.1.17",
|
"@nestjs/swagger": "^7.1.17",
|
||||||
"@nestjs/throttler": "^5.1.1",
|
"@nestjs/throttler": "^5.1.2",
|
||||||
"@prisma/client": "^5.8.1",
|
"@prisma/client": "^5.8.1",
|
||||||
"@prisma/studio": "^0.497.0",
|
"@prisma/studio": "^0.497.0",
|
||||||
"@types/nodemailer": "^6.4.14",
|
"@types/nodemailer": "^6.4.14",
|
||||||
|
2
prisma/migrations/20240607141740_/migration.sql
Normal file
2
prisma/migrations/20240607141740_/migration.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Crypto" ADD COLUMN "quantity" DOUBLE PRECISION NOT NULL DEFAULT 1000;
|
@ -14,6 +14,7 @@ model Crypto {
|
|||||||
name String @unique
|
name String @unique
|
||||||
value Float
|
value Float
|
||||||
image String
|
image String
|
||||||
|
quantity Float @default(1000)
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt @default(now())
|
updated_at DateTime @updatedAt @default(now())
|
||||||
UserHasCrypto UserHasCrypto[]
|
UserHasCrypto UserHasCrypto[]
|
||||||
|
@ -10,6 +10,7 @@ import { CryptoModule } from './crypto/crypto.module';
|
|||||||
import { TradeModule } from './trade/trade.module';
|
import { TradeModule } from './trade/trade.module';
|
||||||
import { OfferModule } from './offer/offer.module';
|
import { OfferModule } from './offer/offer.module';
|
||||||
import { UserModule } from './user/user.module';
|
import { UserModule } from './user/user.module';
|
||||||
|
import { ThrottlerModule } from '@nestjs/throttler';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -24,6 +25,12 @@ import { UserModule } from './user/user.module';
|
|||||||
TradeModule,
|
TradeModule,
|
||||||
OfferModule,
|
OfferModule,
|
||||||
UserModule,
|
UserModule,
|
||||||
|
ThrottlerModule.forRoot([
|
||||||
|
{
|
||||||
|
ttl: 60000,
|
||||||
|
limit: 40,
|
||||||
|
},
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
|
@ -57,6 +57,7 @@ export class CryptoService {
|
|||||||
name: dto.name,
|
name: dto.name,
|
||||||
image: dto.image,
|
image: dto.image,
|
||||||
value: dto.value,
|
value: dto.value,
|
||||||
|
quantity: dto.quantity,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -75,7 +76,9 @@ export class CryptoService {
|
|||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (crypto.quantity < dto.amount) {
|
||||||
|
throw new ForbiddenException('No more tokens available');
|
||||||
|
}
|
||||||
const necessaryAmount = crypto.value * dto.amount;
|
const necessaryAmount = crypto.value * dto.amount;
|
||||||
console.log(necessaryAmount, user.dollarAvailables);
|
console.log(necessaryAmount, user.dollarAvailables);
|
||||||
|
|
||||||
|
@ -17,6 +17,14 @@ export class CryptoDto {
|
|||||||
@IsNumber()
|
@IsNumber()
|
||||||
value: number;
|
value: number;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: Number,
|
||||||
|
description: 'Quantity of tokens available on the platform',
|
||||||
|
example: 100,
|
||||||
|
})
|
||||||
|
@IsNumber()
|
||||||
|
quantity: number;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
type: String,
|
type: String,
|
||||||
description: 'Image for the cryptocurrency in ',
|
description: 'Image for the cryptocurrency in ',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user