FoundKey/packages/backend/src/models/repositories/abuse-user-report.ts
Johann150 37e47a257e
Some checks failed
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed
fix lints "import/order" and "import/no-duplicate"
Also simplified some import paths by replacing relative with absolute paths.
2022-08-03 14:05:50 +02:00

39 lines
1.1 KiB
TypeScript

import { db } from '@/db/postgre.js';
import { AbuseUserReport } from '@/models/entities/abuse-user-report.js';
import { awaitAll } from '@/prelude/await-all.js';
import { Users } from '../index.js';
export const AbuseUserReportRepository = db.getRepository(AbuseUserReport).extend({
async pack(
src: AbuseUserReport['id'] | AbuseUserReport,
) {
const report = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
return await awaitAll({
id: report.id,
createdAt: report.createdAt.toISOString(),
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,
forwarded: report.forwarded,
urls: report.urls,
});
},
packMany(
reports: any[],
) {
return Promise.all(reports.map(x => this.pack(x)));
},
});