Добавил роут для поиска
This commit is contained in:
parent
fe77b55275
commit
7d4e2c7b91
|
|
@ -28,6 +28,11 @@ export class BlacklistController {
|
|||
return this.blacklistService.getAllRecords();
|
||||
}
|
||||
|
||||
@Get('/search')
|
||||
async searchReports(@Query('text') text: string): Promise<BlacklistItemList> {
|
||||
return this.blacklistService.searchReports(text);
|
||||
}
|
||||
|
||||
@Get('/by_link')
|
||||
async getReportsByLink(
|
||||
@Query('link') link: string,
|
||||
|
|
|
|||
|
|
@ -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<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> {
|
||||
const allRecords: BlacklistReport[] =
|
||||
await this.blacklistReportModel.findAll({
|
||||
|
|
|
|||
Loading…
Reference in New Issue