mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-03-23 04:23:35 +00:00
feat: モデログを検索できるように
This commit is contained in:
@@ -9,6 +9,7 @@ import type { ModerationLogsRepository } from '@/models/_.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { ModerationLogEntityService } from '@/core/entities/ModerationLogEntityService.js';
|
||||
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@@ -67,6 +68,7 @@ export const paramDef = {
|
||||
untilDate: { type: 'integer' },
|
||||
type: { type: 'string', nullable: true },
|
||||
userId: { type: 'string', format: 'misskey:id', nullable: true },
|
||||
search: { type: 'string', nullable: true },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
@@ -81,19 +83,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const query = this.queryService.makePaginationQuery(this.moderationLogsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate);
|
||||
const query = this.queryService.makePaginationQuery(this.moderationLogsRepository.createQueryBuilder('log'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate);
|
||||
|
||||
if (ps.type != null) {
|
||||
query.andWhere('report.type = :type', { type: ps.type });
|
||||
query.andWhere('log.type = :type', { type: ps.type });
|
||||
}
|
||||
|
||||
if (ps.userId != null) {
|
||||
query.andWhere('report.userId = :userId', { userId: ps.userId });
|
||||
query.andWhere('log.userId = :userId', { userId: ps.userId });
|
||||
}
|
||||
|
||||
const reports = await query.limit(ps.limit).getMany();
|
||||
if (ps.search != null) {
|
||||
const escapedSearch = sqlLikeEscape(ps.search);
|
||||
query.andWhere('log.info::text ILIKE :search', { search: `%${escapedSearch}%` });
|
||||
}
|
||||
|
||||
return await this.moderationLogEntityService.packMany(reports);
|
||||
const logs = await query.limit(ps.limit).getMany();
|
||||
|
||||
return await this.moderationLogEntityService.packMany(logs);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user