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