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