From ab276380d4ab68cecf23cba24f1b02d1f254f9d0 Mon Sep 17 00:00:00 2001 From: Kevsl Date: Sun, 9 Jun 2024 01:22:52 +0200 Subject: [PATCH] fixed crypto id on update offer --- src/offer/dto/offer.dto.ts | 3 ++- src/offer/offer.service.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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: {