2022-03-26 06:34:00 +00:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { ModerationLog } from '@/models/entities/moderation-log.js';
|
|
|
|
import { awaitAll } from '@/prelude/await-all.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import { Users } from '../index.js';
|
2019-07-13 18:18:45 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
export const ModerationLogRepository = db.getRepository(ModerationLog).extend({
|
|
|
|
async pack(
|
2019-07-13 18:18:45 +00:00
|
|
|
src: ModerationLog['id'] | ModerationLog,
|
|
|
|
) {
|
2022-03-26 06:34:00 +00:00
|
|
|
const log = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2019-07-13 18:18:45 +00:00
|
|
|
|
|
|
|
return await awaitAll({
|
|
|
|
id: log.id,
|
2022-02-03 11:45:18 +00:00
|
|
|
createdAt: log.createdAt.toISOString(),
|
2019-07-13 18:18:45 +00:00
|
|
|
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
|
|
|
}),
|
|
|
|
});
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
2019-07-13 18:18:45 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
packMany(
|
2019-07-13 18:18:45 +00:00
|
|
|
reports: any[],
|
|
|
|
) {
|
|
|
|
return Promise.all(reports.map(x => this.pack(x)));
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
|
|
|
});
|