forked from Yara724/api
Merge pull request 'YARA-1061, Fixed v3 mirror flow' (#195) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#195
This commit is contained in:
@@ -10598,42 +10598,46 @@ export class ClaimRequestManagementService {
|
||||
actor,
|
||||
);
|
||||
|
||||
// V4/V5 (in-person FileReviewer flow): car-capture is the last step.
|
||||
// Both variants land at WAITING_FOR_DAMAGE_EXPERT here.
|
||||
// For V5 (requiresFileMakerApproval=true), autoSubmitToFanavaranV2OnClaimCompleted
|
||||
// intercepts COMPLETED → WAITING_FOR_FILE_MAKER_APPROVAL after expert review.
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
|
||||
$set: {
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
claimStatus: ClaimStatus.PENDING,
|
||||
"workflow.currentStep": ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
"workflow.nextStep": ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
},
|
||||
$push: {
|
||||
"workflow.completedSteps": ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
history: {
|
||||
type: "STEP_COMPLETED",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(currentUserId),
|
||||
actorName: claimCase.owner?.fullName || "User",
|
||||
actorType: actor?.role === RoleEnum.FILE_REVIEWER ? "file_reviewer" : "user",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: {
|
||||
stepKey: ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
description: "V4/V5 walk-around video uploaded. Claim ready for damage expert review.",
|
||||
v3InPersonFlow: true,
|
||||
// V4/V5 only (isMadeByFileMaker): car-capture is the FINAL FileReviewer step.
|
||||
// For the v3 mirror (FIELD_EXPERT IN_PERSON), car-capture is penultimate —
|
||||
// expertUploadBlameVideoV3 finalises the blame with the accident video next.
|
||||
if ((blame as any).isMadeByFileMaker) {
|
||||
// Both V4 and V5 land at WAITING_FOR_DAMAGE_EXPERT here.
|
||||
// For V5 (requiresFileMakerApproval=true), autoSubmitToFanavaranV2OnClaimCompleted
|
||||
// intercepts COMPLETED → WAITING_FOR_FILE_MAKER_APPROVAL after expert review.
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
|
||||
$set: {
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
claimStatus: ClaimStatus.PENDING,
|
||||
"workflow.currentStep": ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
"workflow.nextStep": ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
},
|
||||
$push: {
|
||||
"workflow.completedSteps": ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
history: {
|
||||
type: "STEP_COMPLETED",
|
||||
actor: {
|
||||
actorId: new Types.ObjectId(currentUserId),
|
||||
actorName: claimCase.owner?.fullName || "User",
|
||||
actorType: actor?.role === RoleEnum.FILE_REVIEWER ? "file_reviewer" : "user",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: {
|
||||
stepKey: ClaimWorkflowStep.USER_SUBMISSION_COMPLETE,
|
||||
description: "V4/V5 walk-around video uploaded. Claim ready for damage expert review.",
|
||||
v3InPersonFlow: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Mark the linked blame file as COMPLETED.
|
||||
if (claimCase.blameRequestId) {
|
||||
await this.blameRequestDbService.findByIdAndUpdate(
|
||||
String(claimCase.blameRequestId),
|
||||
{ $set: { status: BlameCaseStatus.COMPLETED } },
|
||||
);
|
||||
// Mark the linked blame file as COMPLETED.
|
||||
if (claimCase.blameRequestId) {
|
||||
await this.blameRequestDbService.findByIdAndUpdate(
|
||||
String(claimCase.blameRequestId),
|
||||
{ $set: { status: BlameCaseStatus.COMPLETED } },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -368,6 +368,8 @@ export class InquiryRefreshService {
|
||||
|
||||
next.insurance.policyNumber =
|
||||
mapped.PrntPlcyCmpDocNo ||
|
||||
mapped.printNumber ||
|
||||
mapped.insuranceNumber ||
|
||||
next.insurance.policyNumber;
|
||||
next.insurance.company =
|
||||
mapped.companyPersianName || mapped.CompanyName || next.insurance.company;
|
||||
|
||||
@@ -81,5 +81,33 @@ describe("SandHubService inquiry mocks", () => {
|
||||
expect(httpService.post).not.toHaveBeenCalled();
|
||||
expect(result.mapped?.CompanyName).toBe("بیمه پارسیان");
|
||||
expect(result.mapped?.CompanyCode).toBe("8");
|
||||
// PrntPlcyCmpDocNo must be populated from the mock raw field
|
||||
expect(result.mapped?.PrntPlcyCmpDocNo).toBe("1404/1143-70591/200/123");
|
||||
});
|
||||
|
||||
it("maps printNumber → PrntPlcyCmpDocNo when raw response uses new field name", async () => {
|
||||
// Simulate a real-API response where the policy number arrives as printNumber
|
||||
const rawNewFormat = {
|
||||
printNumber: "1405/1143-NEWAPI/200/1",
|
||||
CompanyName: "بیمه آزمایشی",
|
||||
CompanyCode: "99",
|
||||
FinancialCvrCptl: "5000000000",
|
||||
IssueDate: "1405/01/01",
|
||||
EndDate: "1406/01/01",
|
||||
};
|
||||
const mapped = (service as any).mapNewApiResponseToOldFormat(rawNewFormat);
|
||||
|
||||
expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-NEWAPI/200/1");
|
||||
});
|
||||
|
||||
it("maps insuranceNumber → PrntPlcyCmpDocNo when raw response uses legacy field name", async () => {
|
||||
const rawLegacy = {
|
||||
insuranceNumber: "1405/1143-LEGACY/200/1",
|
||||
CompanyName: "بیمه آزمایشی",
|
||||
CompanyCode: "99",
|
||||
};
|
||||
const mapped = (service as any).mapNewApiResponseToOldFormat(rawLegacy);
|
||||
|
||||
expect(mapped.PrntPlcyCmpDocNo).toBe("1405/1143-LEGACY/200/1");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1012,11 +1012,20 @@ export class SandHubService {
|
||||
IssueDate: newResponse.persianStartDate || newResponse.IssueDate,
|
||||
EndDate: newResponse.persianEndDate || newResponse.EndDate,
|
||||
|
||||
// Insurance policy number — canonical Tejarat name is PrntPlcyCmpDocNo;
|
||||
// newer API formats surface it as printNumber or insuranceNumber.
|
||||
PrntPlcyCmpDocNo:
|
||||
newResponse.PrntPlcyCmpDocNo ||
|
||||
newResponse.printNumber ||
|
||||
newResponse.insuranceNumber ||
|
||||
null,
|
||||
|
||||
// Insurance details
|
||||
LastCompanyDocumentNumber:
|
||||
newResponse.lastCompanyInsuranceNumber ||
|
||||
newResponse.LastCompanyDocumentNumber ||
|
||||
newResponse.insuranceNumber,
|
||||
newResponse.insuranceNumber ||
|
||||
null,
|
||||
|
||||
// Technical details
|
||||
MtrNum: newResponse.MtrNum || newResponse.mtrnum,
|
||||
|
||||
Reference in New Issue
Block a user