feat: complete reporting and filing workflows
This commit is contained in:
@@ -20,8 +20,8 @@ export interface ReviewCertificationDto {
|
||||
export class CertificationService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
list(tenantId?: string, status?: string, keyword?: string) {
|
||||
return this.prisma.enterpriseCertification.findMany({
|
||||
async list(tenantId?: string, status?: string, keyword?: string) {
|
||||
const records = await this.prisma.enterpriseCertification.findMany({
|
||||
where: {
|
||||
tenantId,
|
||||
status: status && status !== 'all' ? status : undefined,
|
||||
@@ -36,6 +36,7 @@ export class CertificationService {
|
||||
include: { tenant: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return this.attachReviewers(records);
|
||||
}
|
||||
|
||||
async get(id: string) {
|
||||
@@ -46,7 +47,7 @@ export class CertificationService {
|
||||
if (!certification) {
|
||||
throw new NotFoundException('Enterprise certification not found');
|
||||
}
|
||||
return certification;
|
||||
return (await this.attachReviewers([certification]))[0];
|
||||
}
|
||||
|
||||
async submit(data: SubmitCertificationDto) {
|
||||
@@ -97,8 +98,12 @@ export class CertificationService {
|
||||
if (!certification) {
|
||||
throw new NotFoundException('Enterprise certification not found');
|
||||
}
|
||||
let reviewer: { id: string; username: string; displayName: string } | null = null;
|
||||
if (data.reviewerId) {
|
||||
const reviewer = await this.prisma.user.findUnique({ where: { id: data.reviewerId }, select: { id: true } });
|
||||
reviewer = await this.prisma.user.findUnique({
|
||||
where: { id: data.reviewerId },
|
||||
select: { id: true, username: true, displayName: true },
|
||||
});
|
||||
if (!reviewer) {
|
||||
throw new BadRequestException('reviewerId does not reference an existing user');
|
||||
}
|
||||
@@ -126,6 +131,19 @@ export class CertificationService {
|
||||
detail: { reason: data.reason } as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
return updated;
|
||||
return { ...updated, reviewer };
|
||||
}
|
||||
|
||||
private async attachReviewers<T extends { reviewerId: string | null }>(records: T[]) {
|
||||
const reviewerIds = [...new Set(records.map((record) => record.reviewerId).filter((id): id is string => Boolean(id)))];
|
||||
const reviewers = reviewerIds.length ? await this.prisma.user.findMany({
|
||||
where: { id: { in: reviewerIds } },
|
||||
select: { id: true, username: true, displayName: true },
|
||||
}) : [];
|
||||
const reviewerById = new Map(reviewers.map((reviewer) => [reviewer.id, reviewer]));
|
||||
return records.map((record) => ({
|
||||
...record,
|
||||
reviewer: record.reviewerId ? reviewerById.get(record.reviewerId) ?? null : null,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user