feat: モデログを検索できるように

This commit is contained in:
syuilo
2025-06-28 21:38:54 +09:00
parent 3c5ed0ffbb
commit 3c6f07fc8c
4 changed files with 37 additions and 9 deletions

View File

@@ -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);
});
}
}