From cf0e157ad408bfb22837195b602bb31f812a5b97 Mon Sep 17 00:00:00 2001 From: Dhaverd Date: Sat, 2 May 2026 14:59:11 +0800 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=BE=D1=83=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/blacklist/blacklist.controller.ts | 30 ++++++++++++++-- src/modules/blacklist/blacklist.service.ts | 35 +++++++++++++++++++ src/modules/blacklist/dto/blacklistReport.ts | 1 + .../blacklist/models/blacklistReport.model.ts | 14 ++++---- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/modules/blacklist/blacklist.controller.ts b/src/modules/blacklist/blacklist.controller.ts index 93fd38f..bfd4435 100644 --- a/src/modules/blacklist/blacklist.controller.ts +++ b/src/modules/blacklist/blacklist.controller.ts @@ -1,4 +1,14 @@ -import { BadRequestException, Body, Controller, Get, Post, Query } from '@nestjs/common'; +import { + BadRequestException, + Body, + Controller, + Get, + Param, + Post, + Delete, + Put, + Query, +} from '@nestjs/common'; import { BlacklistService } from './blacklist.service'; import { BlacklistItemList } from './types/blacklistItemList'; import { BlacklistReport } from './models/blacklistReport.model'; @@ -6,8 +16,7 @@ import * as blacklistReport from './dto/blacklistReport'; @Controller('api/v1/blacklist') export class BlacklistController { - constructor(private readonly blacklistService: BlacklistService) { - } + constructor(private readonly blacklistService: BlacklistService) {} @Get('/health_check') getHello(): string { @@ -41,4 +50,19 @@ export class BlacklistController { blacklistReportDto, ); } + + @Put('/edit') + async updateReport( + @Body() + blacklistReportDto: blacklistReport.BlacklistReportDto, + ): Promise { + return await this.blacklistService.updateBlacklistRecord( + blacklistReportDto, + ); + } + + @Delete('/delete/:steamLink') + async deleteReport(@Param('steamLink') steamLink: string): Promise { + return await this.blacklistService.deleteBlacklistRecord(steamLink); + } } diff --git a/src/modules/blacklist/blacklist.service.ts b/src/modules/blacklist/blacklist.service.ts index 88cbbdf..d606808 100644 --- a/src/modules/blacklist/blacklist.service.ts +++ b/src/modules/blacklist/blacklist.service.ts @@ -4,6 +4,7 @@ import { BlacklistReport } from './models/blacklistReport.model'; import { BlacklistItem } from './types/blacklistItem'; import { BlacklistItemList } from './types/blacklistItemList'; import { BlacklistReportDto } from './dto/blacklistReport'; +import { BadRequestException } from '@nestjs/common'; @Injectable() export class BlacklistService { @@ -65,4 +66,38 @@ export class BlacklistService { const report = BlacklistReport.build(blackListReportDto); return await report.save(); } + + async updateBlacklistRecord( + blackListReportDto: BlacklistReportDto, + ): Promise { + const record = await this.blacklistReportModel.findOne({ + where: { id: blackListReportDto.id }, + raw: false, + }); + + if (!record) { + throw new BadRequestException('Record not found', { + cause: new Error(), + description: `Report with id ${blackListReportDto.id} does not exist in the blacklist`, + }); + } + + // Update fields with validation to ensure types are correct + record.steam_link = blackListReportDto.steam_link; + record.comment = blackListReportDto.comment; + record.toxic = blackListReportDto.toxic; + record.cheater = blackListReportDto.cheater; + record.afk = blackListReportDto.afk; + record.useless = blackListReportDto.useless; + record.griefer = blackListReportDto.griefer; + + return await record.save(); + } + + async deleteBlacklistRecord(steamLink: string): Promise { + const deletedCount = await this.blacklistReportModel.destroy({ + where: { steam_link: steamLink }, + }); + return deletedCount > 0; + } } diff --git a/src/modules/blacklist/dto/blacklistReport.ts b/src/modules/blacklist/dto/blacklistReport.ts index a8bf526..8157e7d 100644 --- a/src/modules/blacklist/dto/blacklistReport.ts +++ b/src/modules/blacklist/dto/blacklistReport.ts @@ -1,4 +1,5 @@ export type BlacklistReportDto = { + id: number; steam_link: string; comment: string; toxic: boolean; diff --git a/src/modules/blacklist/models/blacklistReport.model.ts b/src/modules/blacklist/models/blacklistReport.model.ts index 3a12fea..e4b807e 100644 --- a/src/modules/blacklist/models/blacklistReport.model.ts +++ b/src/modules/blacklist/models/blacklistReport.model.ts @@ -3,23 +3,23 @@ import { Column, Model, Table } from 'sequelize-typescript'; @Table export class BlacklistReport extends Model { @Column - steam_link: string; + declare steam_link: string; @Column - comment: string; + declare comment: string; @Column({ defaultValue: false }) - toxic: boolean; + declare toxic: boolean; @Column({ defaultValue: false }) - cheater: boolean; + declare cheater: boolean; @Column({ defaultValue: false }) - afk: boolean; + declare afk: boolean; @Column({ defaultValue: false }) - useless: boolean; + declare useless: boolean; @Column({ defaultValue: false }) - griefer: boolean; + declare griefer: boolean; }