update the vehicle used , also sharh hardcoded

This commit is contained in:
2026-11-09 18:34:57 +03:30
parent f33eabeb4f
commit cc0d69dcb2
4 changed files with 217 additions and 10 deletions
@@ -1849,7 +1849,7 @@ export class ClaimRequestManagementService {
result.PlaqueSampleId = null;
result.PlaqueSerial = null;
result.PoliceOfficerId = 1;
result.PoliceReportDesc = null;
result.PoliceReportDesc = "شرح گزارش";
result.PoliceReportSeri = null;
result.PoliceReportSerial = null;
result.PolicyId = null;
@@ -2289,6 +2289,14 @@ export class ClaimRequestManagementService {
this.logger.log(
`Policy ${policyId} VehicleId=${vehicleId} version=${versionNo ?? "latest"} VehicleKindId=${parseFanavaranId(vehicle?.VehicleKindId) ?? "none"} UsedId=${parseFanavaranId(vehicle?.UsedId) ?? "none"}`,
);
if (product === "car-body") {
// The hull claim belongs to this policy's exact vehicle version.
// A generic lookup's first/personal row is not an inquiry result.
return {
usedId: parseFanavaranId(vehicle?.UsedId),
vehicleKindId: parseFanavaranId(vehicle?.VehicleKindId),
};
}
return this.resolveAccidentVehicleUsedFromVehicleRecord(
clientKey,
vehicle,
@@ -2314,6 +2322,20 @@ export class ClaimRequestManagementService {
vehicleKindId: number | null;
source: "vin-inquiry" | "policy-vehicle" | null;
}> {
if (input.product === "car-body") {
if (typeof input.policyId !== "number") {
return { usedId: null, vehicleKindId: null, source: null };
}
const resolved = await this.resolveAccidentVehicleUsedFromPolicy(
input.clientKey,
input.policyId,
"car-body",
);
return {
...resolved,
source: resolved.usedId == null ? null : "policy-vehicle",
};
}
const guiltyParty = (input.parties ?? []).find(
(party: any) =>
String(party?.person?.userId ?? "") ===
@@ -4376,8 +4398,8 @@ export class ClaimRequestManagementService {
persistPayload?: boolean;
/**
* Re-run VIN inquiry / vehicle GET for AccidentVehicleUsedId.
* Submit always re-inquires. If the API still returns nothing, the
* tenant config default is used.
* Hull always reads UsedId from the policy's vehicle version; unresolved
* hull values produce a preview warning and block submit.
*/
forceRefreshUsedId?: boolean;
},
@@ -4660,6 +4682,7 @@ export class ClaimRequestManagementService {
payload.AccidentTime = carBodyAccidentTime.trim();
}
const isHull = blameCase.type === BlameRequestType.CAR_BODY;
const cachedUsedId =
forceRefreshUsedId || forceRefreshPolicy
? null
@@ -4667,6 +4690,7 @@ export class ClaimRequestManagementService {
const cachedUsedSource = (claimCase as any)?.fanavaranSync?.baseClaim
?.accidentVehicleUsedSource;
const canReuseApiUsedId =
!isHull &&
!forceRefreshUsedId &&
!forceRefreshPolicy &&
cachedUsedId != null &&
@@ -4705,17 +4729,32 @@ export class ClaimRequestManagementService {
const approvedUseTypeId = Number(
(claimCase as any)?.fanavaranVehicleReview?.vehicleUseType?.id,
);
if (Number.isInteger(approvedUseTypeId) && approvedUseTypeId > 0) {
if (!isHull && Number.isInteger(approvedUseTypeId) && approvedUseTypeId > 0) {
payload.AccidentVehicleUsedId = approvedUseTypeId;
usedSource = "expert-review";
}
if (parseFanavaranId(payload.AccidentVehicleUsedId) == null) {
payload.AccidentVehicleUsedId = profile.defaults.AccidentVehicleUsedId;
this.logger.log(
`${logPrefix} AccidentVehicleUsedId API miss; using config default ${payload.AccidentVehicleUsedId}`,
);
if (isHull) {
payload.AccidentVehicleUsedId = null;
const warning = {
code: "FANAVARAN_HULL_VEHICLE_USE_UNRESOLVED",
message: `AccidentVehicleUsedId unresolved: policy ${payload.PolicyId ?? "unknown"} vehicle inquiry did not return UsedId. Read the hull policy VehicleId/VehicleVersionNo and retry the vehicle inquiry.`,
field: "AccidentVehicleUsedId",
};
previewWarnings.push(warning);
if (requirePolicyId) throw new BadRequestException(warning);
} else {
payload.AccidentVehicleUsedId = profile.defaults.AccidentVehicleUsedId;
this.logger.log(
`${logPrefix} AccidentVehicleUsedId API miss; using config default ${payload.AccidentVehicleUsedId}`,
);
}
}
Object.assign(debug.values, {
accidentVehicleUsedId: payload.AccidentVehicleUsedId,
accidentVehicleUsedSource: usedSource,
});
if (fanavaranClaimProductFromBlameType(blameCase.type) === "car-body") {
await this.enrichCarBodyHullBaseClaimPayload({
@@ -4808,7 +4847,13 @@ export class ClaimRequestManagementService {
...(payload.PolicyId != null
? { "fanavaranSync.baseClaim.policyId": payload.PolicyId }
: {}),
...(typeof payload.AccidentVehicleUsedId === "number"
...(isHull
? {
"fanavaranSync.baseClaim.accidentVehicleUsedId":
payload.AccidentVehicleUsedId,
"fanavaranSync.baseClaim.accidentVehicleUsedSource": usedSource,
}
: typeof payload.AccidentVehicleUsedId === "number"
? {
"fanavaranSync.baseClaim.accidentVehicleUsedId":
payload.AccidentVehicleUsedId,