Fix damaged vehicle identity across claim panels and price estimates

This commit is contained in:
SepehrYahyaee
2026-10-06 14:20:15 +03:30
parent b11128c638
commit 4564798db1
10 changed files with 375 additions and 199 deletions
+55
View File
@@ -0,0 +1,55 @@
import { resolveClaimBeneficiary } from "./blame-claim-eligibility";
import { resolveVehicleIdentity } from "./vehicle-identity";
/** Resolve the damaged car once for panel responses and AI requests alike. */
export function resolveClaimVehicleSources(claim: any, blame: any) {
const beneficiary = blame ? resolveClaimBeneficiary(blame) : null;
const beneficiaryId =
beneficiary?.person?.userId ?? claim?.damagedPartyUserId;
const parties = blame?.parties?.length
? blame.parties
: claim?.snapshot?.parties;
const party =
beneficiary ??
parties?.find(
(p: any) =>
beneficiaryId && String(p.person?.userId) === String(beneficiaryId),
);
const isBeneficiaryOwner =
beneficiaryId && String(claim?.owner?.userId) === String(beneficiaryId);
const standaloneOwner =
!claim?.blameRequestId &&
!blame &&
!claim?.snapshot?.parties?.length &&
!beneficiaryId &&
!!claim?.owner?.userId;
const snapshot =
isBeneficiaryOwner || standaloneOwner ? (claim?.vehicle ?? {}) : {};
const role =
party?.role ?? (isBeneficiaryOwner ? claim?.owner?.userRole : undefined);
const bodyPolicy = role
? claim?.inquiries?.carBody?.data?.[role]?.mapped
: undefined;
const thirdPolicy = role
? claim?.inquiries?.thirdParty?.data?.[role]?.mapped
: undefined;
const records =
blame?.type === "CAR_BODY"
? [bodyPolicy, thirdPolicy]
: [thirdPolicy, bodyPolicy];
// Retain saved claim details only when that snapshot's owner is verified above.
const vehicle = { ...snapshot, ...(party?.vehicle ?? {}) };
const inquiry = vehicle.inquiry?.mapped ?? vehicle.inquiry ?? {};
const policy = records.find(Boolean) ?? {};
const review = claim?.fanavaranVehicleReview;
const identity = resolveVehicleIdentity(vehicle, records, review);
return {
party,
vehicle,
inquiry,
policy,
snapshot,
review: review?.approved === true ? review : {},
identity,
};
}