fix: enforce drainage uniqueness and carrier-specific reporting

This commit is contained in:
hectorzhao
2026-09-14 18:12:38 +08:00
parent ac6449028c
commit 7f9abe3da0
26 changed files with 2637 additions and 965 deletions
+5 -3
View File
@@ -1,4 +1,5 @@
import { BadRequestException, ServiceUnavailableException } from '@nestjs/common';
import { selectDrainageReportTask } from '../common/drainage-report-task';
import { isIP } from 'node:net';
import { parse } from 'tldts';
import type { PrismaService } from '../prisma/prisma.service';
@@ -19,7 +20,7 @@ export type DrainageMaterial = {
url: string;
auditStatus: string;
materialVersion: number;
reportTasks: Array<{ id: string; channelId: string; carrier: string | null; status: string }>;
reportTasks: Array<{ id: string; channelId: string; carrier: string | null; approvalScope?: string; status: string }>;
};
export type DrainageAssessment = {
version: string;
@@ -138,8 +139,9 @@ export function assessDrainage(
}
const channels = new Set(
approved.flatMap((item) =>
item.reportTasks
.filter((task) => task.status === 'approved' && (!task.carrier || !carrier || task.carrier === carrier))
[...new Set(item.reportTasks.map((task) => task.channelId))]
.map((channelId) => selectDrainageReportTask(item.reportTasks, channelId, carrier))
.filter((task): task is NonNullable<typeof task> => task?.status === 'approved')
.map((task) => task.channelId),
),
);