2019-07-14 03:18:45 +09:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 21:55:45 +09:00
|
|
|
import { Users } from '../index';
|
2021-08-19 22:04:15 +09:00
|
|
|
import { ModerationLog } from '@/models/entities/moderation-log';
|
|
|
|
import { awaitAll } from '@/prelude/await-all';
|
2019-07-14 03:18:45 +09:00
|
|
|
|
|
|
|
@EntityRepository(ModerationLog)
|
|
|
|
export class ModerationLogRepository extends Repository<ModerationLog> {
|
|
|
|
public async pack(
|
|
|
|
src: ModerationLog['id'] | ModerationLog,
|
|
|
|
) {
|
2021-02-13 15:33:38 +09:00
|
|
|
const log = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2019-07-14 03:18:45 +09:00
|
|
|
|
|
|
|
return await awaitAll({
|
|
|
|
id: log.id,
|
2022-02-03 20:45:18 +09:00
|
|
|
createdAt: log.createdAt.toISOString(),
|
2019-07-14 03:18:45 +09:00
|
|
|
type: log.type,
|
|
|
|
info: log.info,
|
|
|
|
userId: log.userId,
|
|
|
|
user: Users.pack(log.user || log.userId, null, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2019-07-14 03:18:45 +09:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public packMany(
|
|
|
|
reports: any[],
|
|
|
|
) {
|
|
|
|
return Promise.all(reports.map(x => this.pack(x)));
|
|
|
|
}
|
|
|
|
}
|