forked from Yara724/api
Merge pull request 'fix(fanavaran): require vehicle review and recover submitted base claims' (#411) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#411
This commit is contained in:
@@ -43,3 +43,12 @@ The same tab also supports [expert editing of accident and assessment fields](fa
|
|||||||
Base claim, damage case, attachments, and expertise writes enforce the persisted approval. Automatic stages are deferred with a skip reason; manual stages return `409` with code `FANAVARAN_VEHICLE_REVIEW_REQUIRED`. Read-only previews remain available for diagnosis.
|
Base claim, damage case, attachments, and expertise writes enforce the persisted approval. Automatic stages are deferred with a skip reason; manual stages return `409` with code `FANAVARAN_VEHICLE_REVIEW_REQUIRED`. Read-only previews remain available for diagnosis.
|
||||||
|
|
||||||
Once Fanavaran has created the base claim, the review is immutable in the panel because changing it would make the local snapshot disagree with data already written remotely.
|
Once Fanavaran has created the base claim, the review is immutable in the panel because changing it would make the local snapshot disagree with data already written remotely.
|
||||||
|
|
||||||
|
|
||||||
|
## Recovery for previously submitted base claims
|
||||||
|
|
||||||
|
New base submissions (automatic and manual) require vehicle approval. Existing base claims are reused without another POST.
|
||||||
|
|
||||||
|
A case whose base was already submitted without vehicle approval may receive its first approval while `dmgCaseId` and `expertiseId` are absent. This uses the normal authorized review endpoint and active lookup/relationship validation. Approval preserves the existing base IDs and resumes damage submission when selected parts exist. The update compares the current review and stage IDs atomically so a competing approval or submission requires refresh.
|
||||||
|
|
||||||
|
An approved classification stays locked after base submission. Recovery does not rewrite the remote base payload. Base and damage use-type derivation can refer to different parties, so recovery does not impose equality between their use-type fields.
|
||||||
|
|||||||
@@ -6875,7 +6875,7 @@ export class ClaimRequestManagementService {
|
|||||||
throw new ConflictException({
|
throw new ConflictException({
|
||||||
code: 'FANAVARAN_VEHICLE_REVIEW_REQUIRED',
|
code: 'FANAVARAN_VEHICLE_REVIEW_REQUIRED',
|
||||||
message:
|
message:
|
||||||
'An expert must review and approve the vehicle group, use type, system, and kind before any data can be sent to Fanavaran.',
|
'کارشناس باید پیش از ارسال به فناوران، نوع خودرو، نوع استفاده، سیستم و نام خودرو را بررسی و تأیید کند.',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6887,8 +6887,11 @@ export class ClaimRequestManagementService {
|
|||||||
return 'Already submitted to Fanavaran';
|
return 'Already submitted to Fanavaran';
|
||||||
}
|
}
|
||||||
|
|
||||||
// GEN.03 base claim is sent as soon as the local claim exists.
|
try {
|
||||||
// Vehicle review remains required for damage / attachments / expertise only.
|
this.assertFanavaranVehicleReviewApproved(claimCase);
|
||||||
|
} catch {
|
||||||
|
return 'کارشناس باید پیش از ارسال پرونده به فناوران، مشخصات خودرو را بررسی و تأیید کند.';
|
||||||
|
}
|
||||||
|
|
||||||
const clientKey = resolveFanavaranClientKey();
|
const clientKey = resolveFanavaranClientKey();
|
||||||
const notifierAllowed =
|
const notifierAllowed =
|
||||||
@@ -8071,7 +8074,7 @@ export class ClaimRequestManagementService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!existing) throw new NotFoundException('Claim case not found');
|
if (!existing) throw new NotFoundException('Claim case not found');
|
||||||
// Vehicle review is not required for GEN.03 base — only for later stages.
|
this.assertFanavaranVehicleReviewApproved(existing);
|
||||||
const notifierAllowed =
|
const notifierAllowed =
|
||||||
clientKey === 'tejaratno'
|
clientKey === 'tejaratno'
|
||||||
? await this.tejaratNotifierAllowedIds(clientKey)
|
? await this.tejaratNotifierAllowedIds(clientKey)
|
||||||
|
|||||||
@@ -4120,9 +4120,13 @@ export class ExpertClaimService {
|
|||||||
await this.getClaimDetailV2(claimRequestId, actor);
|
await this.getClaimDetailV2(claimRequestId, actor);
|
||||||
const claim = await this.claimCaseDbService.findById(claimRequestId);
|
const claim = await this.claimCaseDbService.findById(claimRequestId);
|
||||||
if (!claim) throw new NotFoundException("Claim request not found");
|
if (!claim) throw new NotFoundException("Claim request not found");
|
||||||
if (claim.claimId != null || claim.claimNo != null) {
|
const baseSent = claim.claimId != null || claim.claimNo != null;
|
||||||
|
// Recover cases created before base submission required vehicle approval.
|
||||||
|
// Never change an approved snapshot or classification already sent downstream.
|
||||||
|
if (baseSent && ((claim as any).fanavaranVehicleReview?.approved === true ||
|
||||||
|
claim.dmgCaseId != null || claim.expertiseId != null)) {
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
"Vehicle classification cannot be changed after the claim was sent to Fanavaran.",
|
"مشخصات تأییدشده خودرو پس از ارسال به فناوران قابل تغییر نیست.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const fields =
|
const fields =
|
||||||
@@ -4209,8 +4213,11 @@ export class ExpertClaimService {
|
|||||||
const updated = await this.claimCaseDbService.findOneAndUpdate(
|
const updated = await this.claimCaseDbService.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
_id: claimRequestId,
|
_id: claimRequestId,
|
||||||
claimId: null,
|
claimId: claim.claimId ?? null,
|
||||||
claimNo: null,
|
claimNo: claim.claimNo ?? null,
|
||||||
|
dmgCaseId: claim.dmgCaseId ?? null,
|
||||||
|
expertiseId: claim.expertiseId ?? null,
|
||||||
|
fanavaranVehicleReview: (claim as any).fanavaranVehicleReview ?? null,
|
||||||
...(fields?.filter ?? {}),
|
...(fields?.filter ?? {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -748,7 +748,11 @@ describe("Expert Fanavaran stage fields", () => {
|
|||||||
it("soft-skips automatic TejaratNo submission until both choices are saved", async () => {
|
it("soft-skips automatic TejaratNo submission until both choices are saved", async () => {
|
||||||
process.env.FANAVARAN_CLIENT = "tejaratno";
|
process.env.FANAVARAN_CLIENT = "tejaratno";
|
||||||
const { management, claim } = setup("third-party", {
|
const { management, claim } = setup("third-party", {
|
||||||
fanavaranVehicleReview: { approved: true },
|
fanavaranVehicleReview: {
|
||||||
|
approved: true,
|
||||||
|
vehicleGroup: { id: 1 }, vehicleUseType: { id: 1 },
|
||||||
|
vehicleSystem: { id: 14 }, vehicleKind: { id: 7456 },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
management.blameRequestDbService = {
|
management.blameRequestDbService = {
|
||||||
findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }),
|
findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }),
|
||||||
|
|||||||
@@ -114,6 +114,56 @@ describe("Fanavaran vehicle review", () => {
|
|||||||
expect(service.claimCaseDbService.findOneAndUpdate).not.toHaveBeenCalled();
|
expect(service.claimCaseDbService.findOneAndUpdate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("recovers an unreviewed base claim and resumes damage submission", async () => {
|
||||||
|
const service = makeService();
|
||||||
|
const claim = { _id: "507f1f77bcf86cd799439012", claimId: 12378660,
|
||||||
|
damage: { selectedParts: ["front-wing"] } };
|
||||||
|
service.claimCaseDbService.findById.mockResolvedValue(claim);
|
||||||
|
service.claimCaseDbService.findOneAndUpdate.mockImplementation((_filter, update) =>
|
||||||
|
Promise.resolve({ ...claim, fanavaranVehicleReview: update.$set.fanavaranVehicleReview }));
|
||||||
|
const result = await service.approveFanavaranVehicleReviewV2(claim._id, {
|
||||||
|
vehicleGroupId: 1, vehicleUseTypeId: 3, vehicleSystemId: 14,
|
||||||
|
vehicleKindId: 7456, confirmed: true,
|
||||||
|
}, actor);
|
||||||
|
expect(result.review.approved).toBe(true);
|
||||||
|
expect(service.claimCaseDbService.findOneAndUpdate.mock.calls[0][0]).toMatchObject({
|
||||||
|
claimId: 12378660, dmgCaseId: null, fanavaranVehicleReview: null,
|
||||||
|
});
|
||||||
|
expect(service.claimRequestManagementService.autoSubmitFanavaranDamageCaseOnOuterPartsSelected)
|
||||||
|
.toHaveBeenCalledWith(claim._id, ["front-wing"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ fanavaranVehicleReview: { approved: true } },
|
||||||
|
{ dmgCaseId: 42 },
|
||||||
|
{ expertiseId: 43 },
|
||||||
|
])("locks submitted classification: %j", async (state) => {
|
||||||
|
const service = makeService();
|
||||||
|
service.claimCaseDbService.findById.mockResolvedValue({ claimId: 12378660, ...state });
|
||||||
|
await expect(service.approveFanavaranVehicleReviewV2("case", {}, actor))
|
||||||
|
.rejects.toBeInstanceOf(ConflictException);
|
||||||
|
expect(service.claimCaseDbService.findOneAndUpdate).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("blocks a new manual base submission before building or posting its payload", async () => {
|
||||||
|
const service = Object.create(ClaimRequestManagementService.prototype) as any;
|
||||||
|
service.logger = { log: jest.fn() };
|
||||||
|
service.claimCaseDbService = { findById: jest.fn().mockResolvedValue({}) };
|
||||||
|
service.previewFanavaranSubmitV2 = jest.fn();
|
||||||
|
await expect(service.executeFanavaranV2Submit("case", "moallem", { PolicyId: 1 }))
|
||||||
|
.rejects.toMatchObject({ response: { code: "FANAVARAN_VEHICLE_REVIEW_REQUIRED" } });
|
||||||
|
expect(service.previewFanavaranSubmitV2).not.toHaveBeenCalled();
|
||||||
|
await expect(service.getFanavaranAutoSubmitSkipReason({})).resolves.toContain("تأیید");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reuses the existing base without requiring review or creating another base", async () => {
|
||||||
|
const service = Object.create(ClaimRequestManagementService.prototype) as any;
|
||||||
|
service.logger = { log: jest.fn() };
|
||||||
|
service.claimCaseDbService = { findById: jest.fn().mockResolvedValue({ claimId: 12378660 }) };
|
||||||
|
await expect(service.executeFanavaranV2Submit("case", "moallem"))
|
||||||
|
.resolves.toMatchObject({ Id: 12378660 });
|
||||||
|
});
|
||||||
|
|
||||||
it("blocks outbound stages until all four values are approved", () => {
|
it("blocks outbound stages until all four values are approved", () => {
|
||||||
const service = Object.create(
|
const service = Object.create(
|
||||||
ClaimRequestManagementService.prototype,
|
ClaimRequestManagementService.prototype,
|
||||||
|
|||||||
Reference in New Issue
Block a user