Добавил роут для поиска

This commit is contained in:
Dhaverd 2026-05-08 00:24:24 +08:00
parent fe77b55275
commit 7d4e2c7b91
2 changed files with 18 additions and 0 deletions

View File

@ -28,6 +28,11 @@ export class BlacklistController {
return this.blacklistService.getAllRecords(); return this.blacklistService.getAllRecords();
} }
@Get('/search')
async searchReports(@Query('text') text: string): Promise<BlacklistItemList> {
return this.blacklistService.searchReports(text);
}
@Get('/by_link') @Get('/by_link')
async getReportsByLink( async getReportsByLink(
@Query('link') link: string, @Query('link') link: string,

View File

@ -5,6 +5,7 @@ import { BlacklistItem } from './types/blacklistItem';
import { BlacklistItemList } from './types/blacklistItemList'; import { BlacklistItemList } from './types/blacklistItemList';
import { BlacklistReportDto } from './dto/blacklistReport'; import { BlacklistReportDto } from './dto/blacklistReport';
import { BadRequestException } from '@nestjs/common'; import { BadRequestException } from '@nestjs/common';
import { Sequelize, Op } from 'sequelize';
@Injectable() @Injectable()
export class BlacklistService { export class BlacklistService {
@ -22,6 +23,18 @@ export class BlacklistService {
return this.groupRecordsByLink(allRecords); return this.groupRecordsByLink(allRecords);
} }
async searchReports(text: string): Promise<BlacklistItemList> {
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<BlacklistItemList> { async getRecordsByLink(link: string): Promise<BlacklistItemList> {
const allRecords: BlacklistReport[] = const allRecords: BlacklistReport[] =
await this.blacklistReportModel.findAll({ await this.blacklistReportModel.findAll({