summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/repositories/abuse-user-report.ts
blob: 039a9924d2f8391d0d77892c7ddcaa45ec177823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { EntityRepository, Repository } from 'typeorm';
import { Users } from '../index';
import { AbuseUserReport } from '@/models/entities/abuse-user-report';
import { awaitAll } from '@/prelude/await-all';

@EntityRepository(AbuseUserReport)
export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
	public async pack(
		src: AbuseUserReport['id'] | AbuseUserReport,
	) {
		const report = typeof src === 'object' ? src : await this.findOneOrFail(src);

		return await awaitAll({
			id: report.id,
			createdAt: report.createdAt,
			comment: report.comment,
			resolved: report.resolved,
			reporterId: report.reporterId,
			targetUserId: report.targetUserId,
			assigneeId: report.assigneeId,
			reporter: Users.pack(report.reporter || report.reporterId, null, {
				detail: true
			}),
			targetUser: Users.pack(report.targetUser || report.targetUserId, null, {
				detail: true
			}),
			assignee: report.assigneeId ? Users.pack(report.assignee || report.assigneeId, null, {
				detail: true
			}) : null,
		});
	}

	public packMany(
		reports: any[],
	) {
		return Promise.all(reports.map(x => this.pack(x)));
	}
}