forked from Yara724/api
Fix damaged vehicle identity across claim panels and price estimates
This commit is contained in:
@@ -3,7 +3,7 @@ import {
|
||||
coerceDamagedPartsMediaToArray,
|
||||
normalizeDamageSelectedParts,
|
||||
} from "src/helpers/outer-damage-parts";
|
||||
import { resolveClaimBeneficiary } from "src/helpers/blame-claim-eligibility";
|
||||
import { resolveClaimVehicleSources } from "src/helpers/claim-vehicle-identity";
|
||||
import {
|
||||
CreatePriceEstimateDto,
|
||||
EstimatePartQuality,
|
||||
@@ -42,44 +42,9 @@ export function buildEstimateContext(
|
||||
options: CreatePriceEstimateDto,
|
||||
now = new Date(),
|
||||
): EstimateContext {
|
||||
const beneficiary = blame ? resolveClaimBeneficiary(blame) : null;
|
||||
const beneficiaryId =
|
||||
beneficiary?.person?.userId ?? claim?.damagedPartyUserId;
|
||||
const sourceParties = blame?.parties?.length
|
||||
? blame.parties
|
||||
: claim?.snapshot?.parties;
|
||||
const party =
|
||||
beneficiary ??
|
||||
sourceParties?.find(
|
||||
(p: any) =>
|
||||
beneficiaryId && String(p.person?.userId) === String(beneficiaryId),
|
||||
);
|
||||
const vehicle = party?.vehicle ?? {};
|
||||
const inquiry = vehicle.inquiry?.mapped ?? vehicle.inquiry ?? {};
|
||||
// FIRST inquiry on a third-party claim belongs to the culprit. Use only the resolved damaged party's role.
|
||||
const policy = party?.role
|
||||
? (claim?.inquiries?.carBody?.data?.[party.role]?.mapped ??
|
||||
claim?.inquiries?.thirdParty?.data?.[party.role]?.mapped ??
|
||||
{})
|
||||
: {};
|
||||
const review = claim?.fanavaranVehicleReview?.approved
|
||||
? claim.fanavaranVehicleReview
|
||||
: {};
|
||||
const isBeneficiaryOwner =
|
||||
beneficiaryId && String(claim?.owner?.userId) === String(beneficiaryId);
|
||||
// An absent blame record does not make a historical culprit-owned snapshot safe.
|
||||
// Only standalone legacy claims can use their owner as the beneficiary fallback.
|
||||
const standaloneOwner =
|
||||
!claim?.blameRequestId &&
|
||||
!blame &&
|
||||
!claim?.snapshot?.parties?.length &&
|
||||
!beneficiaryId &&
|
||||
!!claim?.owner?.userId;
|
||||
const snapshot =
|
||||
isBeneficiaryOwner || standaloneOwner ? (claim?.vehicle ?? {}) : {};
|
||||
const { party, vehicle, inquiry, policy, snapshot, review, identity } =
|
||||
resolveClaimVehicleSources(claim, blame);
|
||||
const bodyType = text(snapshot.carType ?? vehicle.type);
|
||||
const cleanName = (raw: unknown) =>
|
||||
text(raw) === bodyType ? null : text(raw);
|
||||
const rawYear =
|
||||
options.modelYear ??
|
||||
positive(
|
||||
@@ -175,6 +140,10 @@ export function buildEstimateContext(
|
||||
warnings.push(
|
||||
"هویت خودروی زیاندیده در اطلاعات طرفین مشخص نیست؛ نام یا مدل خودرو ممکن است ناقص باشد.",
|
||||
);
|
||||
if (identity.conflictingNames)
|
||||
warnings.push(
|
||||
"نام خودرو در فیلدهای استعلام همخوان نیست؛ تیپ تأییدنشده ارسال نشد و اطلاعات خودرو نیاز به بررسی کارشناس دارد.",
|
||||
);
|
||||
if (
|
||||
parts.some(
|
||||
(part) => !photos.some((photo) => photo.partKey === part.partKey),
|
||||
@@ -192,17 +161,8 @@ export function buildEstimateContext(
|
||||
partQuality: options.partQuality ?? EstimatePartQuality.OEM,
|
||||
},
|
||||
vehicle: {
|
||||
make:
|
||||
text(review.vehicleSystem?.caption) ??
|
||||
cleanName(vehicle.name) ??
|
||||
text(inquiry.SystemField ?? inquiry.MapTypNam) ??
|
||||
text(policy.SystemField ?? policy.MapTypNam) ??
|
||||
cleanName(snapshot.carName),
|
||||
model:
|
||||
text(review.vehicleKind?.caption) ??
|
||||
cleanName(vehicle.model) ??
|
||||
text(inquiry.TypeField ?? policy.TypeField) ??
|
||||
cleanName(snapshot.carModel),
|
||||
make: identity.name ?? null,
|
||||
model: identity.model ?? null,
|
||||
bodyType,
|
||||
vehicleSystemId: positive(review.vehicleSystem?.id),
|
||||
vehicleKindId: positive(review.vehicleKind?.id),
|
||||
|
||||
Reference in New Issue
Block a user