diff --git a/src/crypto/crypto.controller.ts b/src/crypto/crypto.controller.ts index c7e94de..20a3316 100644 --- a/src/crypto/crypto.controller.ts +++ b/src/crypto/crypto.controller.ts @@ -22,20 +22,20 @@ import { BuyCryptoDto } from './dto/buy.crypto.dto'; @ApiTags('crypto') @Controller('crypto') export class CryptoController { - constructor(private promoService: CryptoService) {} + constructor(private cryptoService: CryptoService) {} @Get('/all') getAllPromoCodes(@GetUser() user: User) { - return this.promoService.getCryptos(user.id); + return this.cryptoService.getCryptos(user.id); } @Get('/search/:name') searchCrypto(@GetUser() user: User, @Param('name') cryptoName: string) { - return this.promoService.searchCryptos(user.id, cryptoName); + return this.cryptoService.searchCryptos(user.id, cryptoName); } @Get('/history/:id') CryptoHistory(@GetUser() user: User, @Param('id') cryptoId: string) { - return this.promoService.getCryptoHistory(user.id, cryptoId); + return this.cryptoService.getCryptoHistory(user.id, cryptoId); } @HttpCode(HttpStatus.CREATED) @@ -45,7 +45,7 @@ export class CryptoController { dto: CryptoDto, @GetUser() user: User, ) { - return this.promoService.createCrypto(user.id, dto); + return this.cryptoService.createCrypto(user.id, dto); } @Post('/buy') buyCrypto( @@ -53,6 +53,21 @@ export class CryptoController { dto: BuyCryptoDto, @GetUser() user: User, ) { - return this.promoService.buyCrypto(user.id, dto); + return this.cryptoService.buyCrypto(user.id, dto); + } + @HttpCode(HttpStatus.OK) + @Patch('/update/:id') + editCryptoById( + @Param('id') cryptoId: string, + @Body() dto: CryptoDto, + @GetUser() user: User, + ) { + return this.cryptoService.editCryptoById(user.id, cryptoId, dto); + } + + @HttpCode(HttpStatus.NO_CONTENT) + @Delete('/delete/:id') + deleteOfferById(@Param('id') roleId: string, @GetUser() user: User) { + return this.cryptoService.deleteCryptoById(user.id, roleId); } } diff --git a/src/crypto/crypto.service.ts b/src/crypto/crypto.service.ts index 3aaf9b4..6ebbdad 100644 --- a/src/crypto/crypto.service.ts +++ b/src/crypto/crypto.service.ts @@ -54,6 +54,14 @@ export class CryptoService { async createCrypto(userId: string, dto: CryptoDto) { await checkuserIsAdmin(userId); + const existingCryptosWithSameName = await this.prisma.crypto.findMany({ + where: { + name: dto.name, + }, + }); + if (existingCryptosWithSameName.length > 0) { + throw new ForbiddenException('Name already taken'); + } const crypto = await this.prisma.crypto.create({ data: { name: dto.name,