mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-08 21:50:13 +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/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",
|
||||
|
@ -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",
|
||||
|
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
|
||||
value Float
|
||||
image String
|
||||
quantity Float @default(1000)
|
||||
created_at DateTime @default(now())
|
||||
updated_at DateTime @updatedAt @default(now())
|
||||
UserHasCrypto UserHasCrypto[]
|
||||
|
@ -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 ',
|
||||
|
Loading…
x
Reference in New Issue
Block a user