fixed get my assets

This commit is contained in:
Kevsl 2024-06-07 12:35:47 +02:00
parent 3c0f14b02e
commit 2db99d1354
5 changed files with 11 additions and 67 deletions

View File

@ -1,11 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
IsCreditCard,
IsEmail,
IsNotEmpty,
IsOptional,
IsString,
} from 'class-validator';
export class AuthRegisterDto { export class AuthRegisterDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,

View File

@ -0,0 +1,9 @@
import { IsInt, IsString } from 'class-validator';
export class PromoCodeDto {
@IsString()
name: string;
@IsInt()
value: number;
}

View File

@ -1,12 +1,9 @@
import { import {
Body, Body,
Controller, Controller,
Delete,
Get, Get,
HttpCode, HttpCode,
HttpStatus, HttpStatus,
Param,
Patch,
Post, Post,
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
@ -38,20 +35,4 @@ export class TradeController {
) { ) {
return this.tradeService.createTrade(user.id, dto); 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);
}
} }

View File

@ -145,44 +145,4 @@ export class TradeService {
}); });
return trade; 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,
},
});
}
} }

View File

@ -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 { GetUser } from '../auth/decorator';
import { JwtGuard } from '../auth/guard'; import { JwtGuard } from '../auth/guard';
import { ApiTags } from '@nestjs/swagger'; import { ApiTags } from '@nestjs/swagger';