monkeeShark/packages/backend/src/models/repositories/moderation-logs.ts

31 lines
776 B
TypeScript
Raw Normal View History

2019-07-13 18:18:45 +00:00
import { EntityRepository, Repository } from 'typeorm';
import { Users } from '../index';
import { ModerationLog } from '@/models/entities/moderation-log';
import { awaitAll } from '@/prelude/await-all';
2019-07-13 18:18:45 +00:00
@EntityRepository(ModerationLog)
export class ModerationLogRepository extends Repository<ModerationLog> {
public async pack(
src: ModerationLog['id'] | ModerationLog,
) {
2021-02-13 06:33:38 +00:00
const log = typeof src === 'object' ? src : await this.findOneOrFail(src);
2019-07-13 18:18:45 +00: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, {
2021-12-09 14:58:30 +00:00
detail: true,
2019-07-13 18:18:45 +00:00
}),
});
}
public packMany(
reports: any[],
) {
return Promise.all(reports.map(x => this.pack(x)));
}
}