diff --git a/src/offer/dto/offer.dto.ts b/src/offer/dto/offer.dto.ts index 60b5de4..70bbf7e 100644 --- a/src/offer/dto/offer.dto.ts +++ b/src/offer/dto/offer.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsNumber, IsString } from 'class-validator'; +import { IsNumber, IsPositive, IsString } from 'class-validator'; export class OfferDto { @ApiProperty({ type: String, @@ -16,5 +16,6 @@ export class OfferDto { example: 21, }) @IsNumber() + @IsPositive() amount: number; } diff --git a/src/offer/offer.service.ts b/src/offer/offer.service.ts index 01af708..ca906d2 100644 --- a/src/offer/offer.service.ts +++ b/src/offer/offer.service.ts @@ -43,8 +43,17 @@ export class OfferService { }, }); + const crypto = await this.prisma.crypto.findUnique({ + where: { + id: dto.id_crypto, + }, + }); + if (!crypto || !crypto.id) { + throw new ForbiddenException('Crypto doesnt exist'); + } + if (!offer || offer.id !== offerId) - throw new ForbiddenException('Access to resources denied'); + throw new ForbiddenException('Offer id mandatory'); return this.prisma.role.update({ where: {