forked from Yara724/api
Fixed insurer
This commit is contained in:
@@ -1099,6 +1099,8 @@ export class ExpertInsurerService {
|
||||
|
||||
async retrieveAllFilesOfClient(insurerId: string) {
|
||||
const id = this.getClientId(insurerId);
|
||||
const idStr = String(id);
|
||||
|
||||
const [blameFiles, claimFiles] = await Promise.all([
|
||||
this.getClientBlameFiles(id),
|
||||
this.getClientClaimFiles(id),
|
||||
@@ -1112,11 +1114,7 @@ export class ExpertInsurerService {
|
||||
parties?: Array<{
|
||||
role?: string;
|
||||
fullName?: string;
|
||||
vehicle?: {
|
||||
carName?: string;
|
||||
carModel?: string;
|
||||
plate?: string;
|
||||
};
|
||||
vehicle?: { carName?: string; carModel?: string; plate?: string };
|
||||
}>;
|
||||
blame?: {
|
||||
requestId?: string;
|
||||
@@ -1125,11 +1123,7 @@ export class ExpertInsurerService {
|
||||
parties?: Array<{
|
||||
role?: string;
|
||||
fullName?: string;
|
||||
vehicle?: {
|
||||
carName?: string;
|
||||
carModel?: string;
|
||||
plate?: string;
|
||||
};
|
||||
vehicle?: { carName?: string; carModel?: string; plate?: string };
|
||||
}>;
|
||||
expertNames?: string[];
|
||||
createdAt?: Date | string;
|
||||
@@ -1150,6 +1144,7 @@ export class ExpertInsurerService {
|
||||
}
|
||||
>();
|
||||
|
||||
// Index blame files first
|
||||
for (const b of blameFiles) {
|
||||
const key = String((b as any).publicId || (b as any)._id || "");
|
||||
if (!key) continue;
|
||||
@@ -1163,7 +1158,7 @@ export class ExpertInsurerService {
|
||||
(b as any).requestNo || String((b as any).requestNumber || ""),
|
||||
status: (b as any).status,
|
||||
parties: partiesPreview,
|
||||
expertNames: extractExpertNamesFromBlame(b), // ← add
|
||||
expertNames: extractExpertNamesFromBlame(b),
|
||||
createdAt: (b as any).createdAt,
|
||||
updatedAt: (b as any).updatedAt,
|
||||
};
|
||||
@@ -1173,10 +1168,61 @@ export class ExpertInsurerService {
|
||||
byPublicId.set(key, prev);
|
||||
}
|
||||
|
||||
// For claim files whose blame wasn't in blameFiles (different insurer's blame),
|
||||
// fetch the linked blame directly so we can get vehicle + parties data
|
||||
const claimOnlyBlameIds = claimFiles
|
||||
.filter((c) => {
|
||||
const key = String((c as any).publicId || (c as any)._id || "");
|
||||
return key && !byPublicId.has(key) && (c as any).blameRequestId;
|
||||
})
|
||||
.map((c) => String((c as any).blameRequestId));
|
||||
|
||||
const uniqueBlameIds = [...new Set(claimOnlyBlameIds)].filter(Boolean);
|
||||
|
||||
const linkedBlames =
|
||||
uniqueBlameIds.length > 0
|
||||
? ((await this.blameRequestDbService.find(
|
||||
{
|
||||
_id: {
|
||||
$in: uniqueBlameIds.map((id) => new Types.ObjectId(id)),
|
||||
},
|
||||
},
|
||||
{ lean: true },
|
||||
)) as any[])
|
||||
: [];
|
||||
|
||||
const linkedBlameByPublicId = new Map<string, any>(
|
||||
linkedBlames.map((b) => [String(b.publicId), b]),
|
||||
);
|
||||
|
||||
// Index claim files
|
||||
for (const c of claimFiles) {
|
||||
const key = String((c as any).publicId || (c as any)._id || "");
|
||||
if (!key) continue;
|
||||
const prev = byPublicId.get(key) ?? { publicId: key };
|
||||
|
||||
// If no blame entry yet, use the linked blame for parties/vehicle/fileType
|
||||
if (!prev.blame) {
|
||||
const linkedBlame = linkedBlameByPublicId.get(key);
|
||||
if (linkedBlame) {
|
||||
const partiesFromBlame = this.buildPartiesPreview(
|
||||
linkedBlame.parties,
|
||||
);
|
||||
prev.fileType = prev.fileType ?? linkedBlame.type;
|
||||
prev.blame = {
|
||||
requestId: String(linkedBlame._id),
|
||||
requestNo: linkedBlame.requestNo || "",
|
||||
status: linkedBlame.status,
|
||||
parties: partiesFromBlame,
|
||||
expertNames: extractExpertNamesFromBlame(linkedBlame),
|
||||
createdAt: linkedBlame.createdAt,
|
||||
updatedAt: linkedBlame.updatedAt,
|
||||
};
|
||||
prev.parties = prev.parties ?? partiesFromBlame;
|
||||
prev.createdAt = prev.createdAt ?? linkedBlame.createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
const claimPartiesPreview = this.buildPartiesPreview(
|
||||
(c as any)?.snapshot?.parties,
|
||||
);
|
||||
@@ -1189,7 +1235,7 @@ export class ExpertInsurerService {
|
||||
status: (c as any).status,
|
||||
claimStatus: (c as any).claimStatus,
|
||||
currentStep: (c as any).currentStep,
|
||||
expertNames: extractExpertNamesFromClaim(c), // ← add
|
||||
expertNames: extractExpertNamesFromClaim(c),
|
||||
createdAt: (c as any).createdAt,
|
||||
updatedAt: (c as any).updatedAt,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user