diff --git a/src/modules/blacklist/blacklist.controller.ts b/src/modules/blacklist/blacklist.controller.ts index bfd00d9..bcf0c1c 100644 --- a/src/modules/blacklist/blacklist.controller.ts +++ b/src/modules/blacklist/blacklist.controller.ts @@ -28,6 +28,11 @@ export class BlacklistController { return this.blacklistService.getAllRecords(); } + @Get('/search') + async searchReports(@Query('text') text: string): Promise { + return this.blacklistService.searchReports(text); + } + @Get('/by_link') async getReportsByLink( @Query('link') link: string, diff --git a/src/modules/blacklist/blacklist.service.ts b/src/modules/blacklist/blacklist.service.ts index 118dd7e..7c27d58 100644 --- a/src/modules/blacklist/blacklist.service.ts +++ b/src/modules/blacklist/blacklist.service.ts @@ -5,6 +5,7 @@ import { BlacklistItem } from './types/blacklistItem'; import { BlacklistItemList } from './types/blacklistItemList'; import { BlacklistReportDto } from './dto/blacklistReport'; import { BadRequestException } from '@nestjs/common'; +import { Sequelize, Op } from 'sequelize'; @Injectable() export class BlacklistService { @@ -22,6 +23,18 @@ export class BlacklistService { return this.groupRecordsByLink(allRecords); } + async searchReports(text: string): Promise { + const foundRecords = await this.blacklistReportModel.findAll({ + raw: true, + where: Sequelize.or( + { steam_link: { [Op.substring]: text } }, + { steam_nickname: { [Op.substring]: text } }, + { comment: { [Op.substring]: text } }, + ), + }); + return this.groupRecordsByLink(foundRecords); + } + async getRecordsByLink(link: string): Promise { const allRecords: BlacklistReport[] = await this.blacklistReportModel.findAll({