forked from Yara724/api
YARA-985
This commit is contained in:
@@ -75,6 +75,7 @@ import {
|
||||
extractExpertNamesFromBlame,
|
||||
extractExpertNamesFromClaim,
|
||||
} from "./helper/insurer.helper";
|
||||
import { getEventFaLabel } from "./helper/timeline-fa-labels";
|
||||
import { buildEnrichedDamagedParts } from "src/expert-claim/dto/claim-damaged-part.enricher";
|
||||
|
||||
@Injectable()
|
||||
@@ -2088,4 +2089,77 @@ export class ExpertInsurerService {
|
||||
waiting_for_documents_resend: counts.WAITING_FOR_DOCUMENT_RESEND ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
async getFileTimeline(
|
||||
insurerId: string,
|
||||
publicId: string,
|
||||
): Promise<{ publicId: string; events: object[] }> {
|
||||
if (!publicId?.trim()) {
|
||||
throw new BadRequestException("publicId is required");
|
||||
}
|
||||
|
||||
const id = this.getClientId(insurerId);
|
||||
const [blameFiles, claimFiles] = await Promise.all([
|
||||
this.getClientBlameFiles(id),
|
||||
this.getClientClaimFiles(id),
|
||||
]);
|
||||
|
||||
const blame = blameFiles.find(
|
||||
(b) => String((b as any).publicId) === publicId,
|
||||
);
|
||||
const claim = claimFiles.find(
|
||||
(c) => String((c as any).publicId) === publicId,
|
||||
);
|
||||
|
||||
if (!blame && !claim) {
|
||||
throw new NotFoundException("File not found for this publicId");
|
||||
}
|
||||
|
||||
const events: object[] = [];
|
||||
|
||||
if (blame) {
|
||||
const blameDoc = await this.blameRequestDbService.findById(
|
||||
String((blame as any)._id),
|
||||
);
|
||||
const blameHistory: any[] = (blameDoc as any)?.history ?? [];
|
||||
for (const ev of blameHistory) {
|
||||
events.push({
|
||||
source: "blame",
|
||||
type: ev.type,
|
||||
faLabel: getEventFaLabel(ev),
|
||||
timestamp: ev.timestamp,
|
||||
actor: ev.actor ?? null,
|
||||
metadata: ev.metadata ?? null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (claim) {
|
||||
const claimId = String((claim as any)._id);
|
||||
const rows = (await this.claimCaseDbService.find(
|
||||
{ _id: new Types.ObjectId(claimId) },
|
||||
{ lean: true, select: "history createdAt" },
|
||||
)) as Record<string, unknown>[];
|
||||
const claimHistory: any[] = (rows[0] as any)?.history ?? [];
|
||||
for (const ev of claimHistory) {
|
||||
events.push({
|
||||
source: "claim",
|
||||
type: ev.type,
|
||||
faLabel: getEventFaLabel(ev),
|
||||
timestamp: ev.timestamp,
|
||||
actor: ev.actor ?? null,
|
||||
metadata: ev.metadata ?? null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
events.sort((a: any, b: any) => {
|
||||
const ta = a.timestamp ? new Date(a.timestamp).getTime() : 0;
|
||||
const tb = b.timestamp ? new Date(b.timestamp).getTime() : 0;
|
||||
return ta - tb;
|
||||
});
|
||||
|
||||
// Resolve insurer's client name for context if needed — just return raw events
|
||||
return { publicId, events };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user