forked from Yara724/api
update the vehicle used , also sharh hardcoded
This commit is contained in:
@@ -51,6 +51,13 @@ source: fanavaran-module-docs
|
|||||||
| Store | `claimId`, `claimNo`, `fanavaranSync.baseClaim.*`, history |
|
| Store | `claimId`, `claimNo`, `fanavaranSync.baseClaim.*`, history |
|
||||||
| Consumers | Damage/expertise soft-ensure; UI claim detail |
|
| Consumers | Damage/expertise soft-ensure; UI claim detail |
|
||||||
|
|
||||||
|
Hull base claims always GET the selected hull policy, then GET its `VehicleId`
|
||||||
|
at `VehicleVersionNo`. `AccidentVehicleUsedId` is that vehicle response's
|
||||||
|
`UsedId`. This path does not substitute a guilty-party VIN, cached use id,
|
||||||
|
expert override, tenant default, or a generic lookup row. Missing `UsedId`
|
||||||
|
produces `FANAVARAN_HULL_VEHICLE_USE_UNRESOLVED` in preview and blocks submit.
|
||||||
|
Debug preview exposes `accidentVehicleUsedId` and `accidentVehicleUsedSource`.
|
||||||
|
|
||||||
#### Staff source for ClaimExpertId across request flows
|
#### Staff source for ClaimExpertId across request flows
|
||||||
|
|
||||||
The flows in `docs/Yara724 flows.pdf` share the same base-claim resolver.
|
The flows in `docs/Yara724 flows.pdf` share the same base-claim resolver.
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Built by `buildFanavaranSubmitPayload` then `enrichCarBodyHullBaseClaimPayload`
|
|||||||
| CulpritLicenceNo | شماره گواهینامه | string | **no** | dummy / **user** |
|
| CulpritLicenceNo | شماره گواهینامه | string | **no** | dummy / **user** |
|
||||||
| CulpritLicenceIssuDate | تاریخ صدور گواهینامه | string Jalali | **no** | **system** `"1394/10/13"` |
|
| CulpritLicenceIssuDate | تاریخ صدور گواهینامه | string Jalali | **no** | **system** `"1394/10/13"` |
|
||||||
| CulpritLicenceTypeId | نوع گواهینامه | number | sent | tenant `2` · lookup `driving-licence-types` |
|
| CulpritLicenceTypeId | نوع گواهینامه | number | sent | tenant `2` · lookup `driving-licence-types` |
|
||||||
| AccidentVehicleUsedId | کاربری خودرو | number | **no** | **inquiry** VIN/policy, else tenant |
|
| AccidentVehicleUsedId | کاربری خودرو | number | **no** | **inquiry** hull policy `VehicleId` + `VehicleVersionNo` → vehicle GET `UsedId`; no default or expert override. Unresolved inquiry warns in preview and blocks submit. |
|
||||||
| PoliceOfficerId | افسر | number | sent | **system** `1` |
|
| PoliceOfficerId | افسر | number | sent | **system** `1` |
|
||||||
| IsAccidentOutOfBorder | خارج از مرز | number | sent | **system** `0` |
|
| IsAccidentOutOfBorder | خارج از مرز | number | sent | **system** `0` |
|
||||||
| ArchiveNo | بایگانی | string | yes | null |
|
| ArchiveNo | بایگانی | string | yes | null |
|
||||||
|
|||||||
@@ -1849,7 +1849,7 @@ export class ClaimRequestManagementService {
|
|||||||
result.PlaqueSampleId = null;
|
result.PlaqueSampleId = null;
|
||||||
result.PlaqueSerial = null;
|
result.PlaqueSerial = null;
|
||||||
result.PoliceOfficerId = 1;
|
result.PoliceOfficerId = 1;
|
||||||
result.PoliceReportDesc = null;
|
result.PoliceReportDesc = "شرح گزارش";
|
||||||
result.PoliceReportSeri = null;
|
result.PoliceReportSeri = null;
|
||||||
result.PoliceReportSerial = null;
|
result.PoliceReportSerial = null;
|
||||||
result.PolicyId = null;
|
result.PolicyId = null;
|
||||||
@@ -2289,6 +2289,14 @@ export class ClaimRequestManagementService {
|
|||||||
this.logger.log(
|
this.logger.log(
|
||||||
`Policy ${policyId} VehicleId=${vehicleId} version=${versionNo ?? "latest"} VehicleKindId=${parseFanavaranId(vehicle?.VehicleKindId) ?? "none"} UsedId=${parseFanavaranId(vehicle?.UsedId) ?? "none"}`,
|
`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(
|
return this.resolveAccidentVehicleUsedFromVehicleRecord(
|
||||||
clientKey,
|
clientKey,
|
||||||
vehicle,
|
vehicle,
|
||||||
@@ -2314,6 +2322,20 @@ export class ClaimRequestManagementService {
|
|||||||
vehicleKindId: number | null;
|
vehicleKindId: number | null;
|
||||||
source: "vin-inquiry" | "policy-vehicle" | 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(
|
const guiltyParty = (input.parties ?? []).find(
|
||||||
(party: any) =>
|
(party: any) =>
|
||||||
String(party?.person?.userId ?? "") ===
|
String(party?.person?.userId ?? "") ===
|
||||||
@@ -4376,8 +4398,8 @@ export class ClaimRequestManagementService {
|
|||||||
persistPayload?: boolean;
|
persistPayload?: boolean;
|
||||||
/**
|
/**
|
||||||
* Re-run VIN inquiry / vehicle GET for AccidentVehicleUsedId.
|
* Re-run VIN inquiry / vehicle GET for AccidentVehicleUsedId.
|
||||||
* Submit always re-inquires. If the API still returns nothing, the
|
* Hull always reads UsedId from the policy's vehicle version; unresolved
|
||||||
* tenant config default is used.
|
* hull values produce a preview warning and block submit.
|
||||||
*/
|
*/
|
||||||
forceRefreshUsedId?: boolean;
|
forceRefreshUsedId?: boolean;
|
||||||
},
|
},
|
||||||
@@ -4660,6 +4682,7 @@ export class ClaimRequestManagementService {
|
|||||||
payload.AccidentTime = carBodyAccidentTime.trim();
|
payload.AccidentTime = carBodyAccidentTime.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isHull = blameCase.type === BlameRequestType.CAR_BODY;
|
||||||
const cachedUsedId =
|
const cachedUsedId =
|
||||||
forceRefreshUsedId || forceRefreshPolicy
|
forceRefreshUsedId || forceRefreshPolicy
|
||||||
? null
|
? null
|
||||||
@@ -4667,6 +4690,7 @@ export class ClaimRequestManagementService {
|
|||||||
const cachedUsedSource = (claimCase as any)?.fanavaranSync?.baseClaim
|
const cachedUsedSource = (claimCase as any)?.fanavaranSync?.baseClaim
|
||||||
?.accidentVehicleUsedSource;
|
?.accidentVehicleUsedSource;
|
||||||
const canReuseApiUsedId =
|
const canReuseApiUsedId =
|
||||||
|
!isHull &&
|
||||||
!forceRefreshUsedId &&
|
!forceRefreshUsedId &&
|
||||||
!forceRefreshPolicy &&
|
!forceRefreshPolicy &&
|
||||||
cachedUsedId != null &&
|
cachedUsedId != null &&
|
||||||
@@ -4705,17 +4729,32 @@ export class ClaimRequestManagementService {
|
|||||||
const approvedUseTypeId = Number(
|
const approvedUseTypeId = Number(
|
||||||
(claimCase as any)?.fanavaranVehicleReview?.vehicleUseType?.id,
|
(claimCase as any)?.fanavaranVehicleReview?.vehicleUseType?.id,
|
||||||
);
|
);
|
||||||
if (Number.isInteger(approvedUseTypeId) && approvedUseTypeId > 0) {
|
if (!isHull && Number.isInteger(approvedUseTypeId) && approvedUseTypeId > 0) {
|
||||||
payload.AccidentVehicleUsedId = approvedUseTypeId;
|
payload.AccidentVehicleUsedId = approvedUseTypeId;
|
||||||
usedSource = "expert-review";
|
usedSource = "expert-review";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseFanavaranId(payload.AccidentVehicleUsedId) == null) {
|
if (parseFanavaranId(payload.AccidentVehicleUsedId) == null) {
|
||||||
payload.AccidentVehicleUsedId = profile.defaults.AccidentVehicleUsedId;
|
if (isHull) {
|
||||||
this.logger.log(
|
payload.AccidentVehicleUsedId = null;
|
||||||
`${logPrefix} AccidentVehicleUsedId API miss; using config default ${payload.AccidentVehicleUsedId}`,
|
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") {
|
if (fanavaranClaimProductFromBlameType(blameCase.type) === "car-body") {
|
||||||
await this.enrichCarBodyHullBaseClaimPayload({
|
await this.enrichCarBodyHullBaseClaimPayload({
|
||||||
@@ -4808,7 +4847,13 @@ export class ClaimRequestManagementService {
|
|||||||
...(payload.PolicyId != null
|
...(payload.PolicyId != null
|
||||||
? { "fanavaranSync.baseClaim.policyId": payload.PolicyId }
|
? { "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":
|
"fanavaranSync.baseClaim.accidentVehicleUsedId":
|
||||||
payload.AccidentVehicleUsedId,
|
payload.AccidentVehicleUsedId,
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
||||||
|
|
||||||
|
function setup(vehicle: Record<string, unknown>) {
|
||||||
|
const service = Object.create(ClaimRequestManagementService.prototype) as any;
|
||||||
|
service.logger = { log: jest.fn(), warn: jest.fn(), error: jest.fn() };
|
||||||
|
service.fanavaranLookupService = {
|
||||||
|
bodyPolicyById: jest.fn().mockResolvedValue({
|
||||||
|
PolicyId: 24230396,
|
||||||
|
VehicleId: 5725803,
|
||||||
|
VehicleVersionNo: 1,
|
||||||
|
PolicyUsageTypeId: 2898,
|
||||||
|
}),
|
||||||
|
vehicleById: jest.fn().mockResolvedValue(vehicle),
|
||||||
|
inquiryByVin: jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({ UsedId: 1, VehicleKindId: 8671 }),
|
||||||
|
};
|
||||||
|
service.getFanavaranLookupRows = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(async (_client, name) =>
|
||||||
|
name === "vehicle-kinds"
|
||||||
|
? [{ Id: 8671, VehicleGroupId: 1 }]
|
||||||
|
: [{ Id: 1, IsActive: 1, VehicleGroupId: 1, Caption: "شخصی" }],
|
||||||
|
);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = {
|
||||||
|
clientKey: "moallem",
|
||||||
|
product: "car-body",
|
||||||
|
policyId: 24230396,
|
||||||
|
guiltyPartyId: "other-party",
|
||||||
|
parties: [
|
||||||
|
{ person: { userId: "other-party" }, vehicle: { vin: "OTHER-VIN" } },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
function previewSetup(vehicle: Record<string, unknown>) {
|
||||||
|
const service = setup(vehicle);
|
||||||
|
service.fanavaranAuditService = { generateTrackingCode: () => "test" };
|
||||||
|
service.claimCaseDbService = {
|
||||||
|
findById: jest.fn().mockResolvedValue({
|
||||||
|
blameRequestId: "blame",
|
||||||
|
fanavaranSync: {
|
||||||
|
baseClaim: {
|
||||||
|
policyId: 24230396,
|
||||||
|
accidentVehicleUsedId: 1,
|
||||||
|
accidentVehicleUsedSource: "vin-inquiry",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fanavaranVehicleReview: { vehicleUseType: { id: 1 } },
|
||||||
|
}),
|
||||||
|
findByIdAndUpdate: jest.fn(),
|
||||||
|
};
|
||||||
|
service.blameRequestDbService = {
|
||||||
|
findById: jest.fn().mockResolvedValue({
|
||||||
|
type: "CAR_BODY",
|
||||||
|
parties: [{ role: "FIRST" }],
|
||||||
|
createdAt: new Date("2026-11-09T10:24:00Z"),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
service.enrichCarBodyHullBaseClaimPayload = jest.fn();
|
||||||
|
service.tryResolveFanavaranBaseClaimExpertId = jest.fn().mockResolvedValue({
|
||||||
|
claimExpertId: 5508,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: ["expert"],
|
||||||
|
});
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Hull base-claim vehicle use from policy inquiry", () => {
|
||||||
|
it("uses the policy vehicle version's UsedId without substituting VIN or lookup defaults", async () => {
|
||||||
|
const service = setup({ UsedId: 42, VehicleKindId: 8671 });
|
||||||
|
await expect(
|
||||||
|
service.resolveAccidentVehicleUsedFromApis(input),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
usedId: 42,
|
||||||
|
source: "policy-vehicle",
|
||||||
|
});
|
||||||
|
expect(service.fanavaranLookupService.vehicleById).toHaveBeenCalledWith(
|
||||||
|
"moallem",
|
||||||
|
5725803,
|
||||||
|
1,
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
|
expect(service.fanavaranLookupService.inquiryByVin).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps a missing API UsedId unresolved instead of choosing a lookup row or policy usage id", async () => {
|
||||||
|
const service = setup({ VehicleKindId: 8671 });
|
||||||
|
await expect(
|
||||||
|
service.resolveAccidentVehicleUsedFromApis(input),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
usedId: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("puts the fresh API UsedId in the payload despite cached and expert-reviewed values", async () => {
|
||||||
|
const service = previewSetup({ UsedId: 42, VehicleKindId: 8671 });
|
||||||
|
const result = await service.previewFanavaranSubmitV2("claim", "moallem", {
|
||||||
|
debug: true,
|
||||||
|
});
|
||||||
|
expect(result.payload.AccidentVehicleUsedId).toBe(42);
|
||||||
|
expect(result.debug.values.accidentVehicleUsedSource).toBe(
|
||||||
|
"policy-vehicle",
|
||||||
|
);
|
||||||
|
expect(service.claimCaseDbService.findByIdAndUpdate).toHaveBeenCalledWith(
|
||||||
|
"claim",
|
||||||
|
expect.objectContaining({
|
||||||
|
$set: expect.objectContaining({
|
||||||
|
"fanavaranSync.baseClaim.accidentVehicleUsedId": 42,
|
||||||
|
"fanavaranSync.baseClaim.accidentVehicleUsedSource": "policy-vehicle",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns on preview when the API has no UsedId instead of sending tenant default 1", async () => {
|
||||||
|
const service = previewSetup({ VehicleKindId: 8671 });
|
||||||
|
const result = await service.previewFanavaranSubmitV2("claim", "moallem", {
|
||||||
|
debug: true,
|
||||||
|
});
|
||||||
|
expect(result.payload.AccidentVehicleUsedId).toBeNull();
|
||||||
|
expect(result.previewWarnings).toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "FANAVARAN_HULL_VEHICLE_USE_UNRESOLVED",
|
||||||
|
field: "AccidentVehicleUsedId",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(service.claimCaseDbService.findByIdAndUpdate).toHaveBeenCalledWith(
|
||||||
|
"claim",
|
||||||
|
expect.objectContaining({
|
||||||
|
$set: expect.objectContaining({
|
||||||
|
"fanavaranSync.baseClaim.accidentVehicleUsedId": null,
|
||||||
|
"fanavaranSync.baseClaim.accidentVehicleUsedSource": null,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("blocks submit payload construction when the API has no UsedId", async () => {
|
||||||
|
const service = previewSetup({ VehicleKindId: 8671 });
|
||||||
|
await expect(
|
||||||
|
service.previewFanavaranSubmitV2("claim", "moallem", {
|
||||||
|
requirePolicyId: true,
|
||||||
|
persistPayload: false,
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({
|
||||||
|
response: expect.objectContaining({
|
||||||
|
code: "FANAVARAN_HULL_VEHICLE_USE_UNRESOLVED",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user