From 2db99d13545aceff1cd4af35968549b6d3757b3c Mon Sep 17 00:00:00 2001 From: Kevsl Date: Fri, 7 Jun 2024 12:35:47 +0200 Subject: [PATCH] fixed get my assets --- src/auth/dto/auth.register.dto.ts | 8 +------ src/trade/dto/promoCode.dto.ts | 9 +++++++ src/trade/trade.controller.ts | 19 --------------- src/trade/trade.service.ts | 40 ------------------------------- src/user/user.controller.ts | 2 +- 5 files changed, 11 insertions(+), 67 deletions(-) create mode 100644 src/trade/dto/promoCode.dto.ts diff --git a/src/auth/dto/auth.register.dto.ts b/src/auth/dto/auth.register.dto.ts index 1d533d6..e9eb1d7 100644 --- a/src/auth/dto/auth.register.dto.ts +++ b/src/auth/dto/auth.register.dto.ts @@ -1,11 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { - IsCreditCard, - IsEmail, - IsNotEmpty, - IsOptional, - IsString, -} from 'class-validator'; +import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator'; export class AuthRegisterDto { @ApiProperty({ type: String, diff --git a/src/trade/dto/promoCode.dto.ts b/src/trade/dto/promoCode.dto.ts new file mode 100644 index 0000000..8013811 --- /dev/null +++ b/src/trade/dto/promoCode.dto.ts @@ -0,0 +1,9 @@ +import { IsInt, IsString } from 'class-validator'; + +export class PromoCodeDto { + @IsString() + name: string; + + @IsInt() + value: number; +} diff --git a/src/trade/trade.controller.ts b/src/trade/trade.controller.ts index 4c996b5..8c09a35 100644 --- a/src/trade/trade.controller.ts +++ b/src/trade/trade.controller.ts @@ -1,12 +1,9 @@ import { Body, Controller, - Delete, Get, HttpCode, HttpStatus, - Param, - Patch, Post, UseGuards, } from '@nestjs/common'; @@ -38,20 +35,4 @@ export class TradeController { ) { return this.tradeService.createTrade(user.id, dto); } - - @HttpCode(HttpStatus.OK) - @Patch('/update/:id') - editPromoCodeById( - @Param('id') promoCodeId: string, - @Body() dto: TradeDto, - @GetUser() user: User, - ) { - return this.tradeService.editTradeById(user.id, promoCodeId, dto); - } - - @HttpCode(HttpStatus.NO_CONTENT) - @Delete('/delete/:id') - deletePromoCodeById(@Param('id') promoCodeId: string, @GetUser() user: User) { - return this.tradeService.deleteTradeById(user.id, promoCodeId); - } } diff --git a/src/trade/trade.service.ts b/src/trade/trade.service.ts index f2379ec..6b8fb1a 100644 --- a/src/trade/trade.service.ts +++ b/src/trade/trade.service.ts @@ -145,44 +145,4 @@ export class TradeService { }); return trade; } - - async editTradeById(userId: string, tradeId: string, dto: TradeDto) { - await checkuserIsAdmin(userId); - - const trade = await this.prisma.trade.findUnique({ - where: { - id: tradeId, - }, - }); - - if (!trade || trade.id !== tradeId) - throw new ForbiddenException('Access to resources denied'); - - return this.prisma.trade.update({ - where: { - id: trade.id, - }, - data: { - ...dto, - }, - }); - } - async deleteTradeById(userId: string, id: string) { - await checkuserIsAdmin(userId); - - const trade = await this.prisma.trade.findUnique({ - where: { - id: id, - }, - }); - - if (!trade || trade.id !== id) - throw new ForbiddenException('Access to resources denied'); - - await this.prisma.trade.delete({ - where: { - id: trade.id, - }, - }); - } } diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 5931b5e..f6e80ff 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, UseGuards } from '@nestjs/common'; +import { Controller, Get, UseGuards } from '@nestjs/common'; import { GetUser } from '../auth/decorator'; import { JwtGuard } from '../auth/guard'; import { ApiTags } from '@nestjs/swagger';