fix: support manual accident addresses and expose final Fanavaran completion

Accept and persist address-only locations across user and expert flows, preserve workflow authorization, and include addresses in reports and Fanavaran review. Expose persisted final submission completion so the expert panel can prevent repeat sends.
This commit is contained in:
SepehrYahyaee
2026-11-21 09:45:13 +03:30
parent b63525c863
commit c6022a1646
15 changed files with 244 additions and 25 deletions
@@ -1887,7 +1887,7 @@ export class ClaimRequestManagementService {
private async buildFanavaranSubmitPayload(input: {
accidentReason?: { id?: string | number | null; fanavaran?: number | null };
createdAt?: Date | string;
location?: { lat?: number; lon?: number };
location?: { lat?: number; lon?: number; address?: string };
damageParts?: any[];
resolvePolicyId: () => Promise<number | null>;
logPrefix: string;
@@ -1929,7 +1929,7 @@ export class ClaimRequestManagementService {
result.AccidentTime = this.getTime24Hour(input.createdAt);
}
result.AccidentLocationAddress = FANAVARAN_ACCIDENT_LOCATION_ADDRESS;
result.AccidentLocationAddress = input.location?.address?.trim() || FANAVARAN_ACCIDENT_LOCATION_ADDRESS;
result.EstimateAmount = this.normalizeFanavaranEstimateAmount(
input.damageParts ? this.calculateEstimateAmount(input.damageParts) : 0,
@@ -5891,7 +5891,7 @@ export class ClaimRequestManagementService {
}),
);
const initial: FanavaranFieldValues = {
AccidentLocationAddress: FANAVARAN_ACCIDENT_LOCATION_ADDRESS,
AccidentLocationAddress: blame.parties?.find((party: any) => party.role === 'FIRST')?.location?.address?.trim() || blame.parties?.find((party: any) => party.location?.address?.trim())?.location.address.trim() || FANAVARAN_ACCIDENT_LOCATION_ADDRESS,
AccidentCityId: defaults.AccidentCityId,
AccidentReportTypeId: defaults.AccidentReportTypeId,
DmgHistoryStatus: defaults.DmgHistoryStatus,
@@ -12,6 +12,7 @@ describe("fanavaranClaimReferences", () => {
expertiseId: 22,
}),
).toEqual({
submissionCompleted: true,
claimId: 987654,
claimNo: 123456,
dmgCaseId: 11,
@@ -40,6 +41,7 @@ describe("fanavaranClaimReferences", () => {
},
}),
).toEqual({
submissionCompleted: true,
claimId: 100,
claimNo: 101,
dmgCaseId: 102,
@@ -64,11 +66,30 @@ describe("fanavaranClaimReferences", () => {
expertiseId: 22,
}),
).toEqual({
submissionCompleted: true,
claimId: 987654,
expertiseId: 22,
});
});
it("keeps partial stage codes retryable", () => {
expect(fanavaranClaimReferences({ status: ClaimCaseStatus.COMPLETED, claimId: 1, dmgCaseId: 2 }))
.not.toHaveProperty("submissionCompleted");
});
it("exposes final acceptance independently of local workflow status", () => {
expect(fanavaranClaimReferences({ status: ClaimCaseStatus.EXPERT_REVIEWING, expertiseId: 22 }))
.toEqual({ submissionCompleted: true });
expect(fanavaranClaimReferences({
status: ClaimCaseStatus.COMPLETED,
fanavaranSync: { expertise: { status: "success" } },
})).toEqual({ submissionCompleted: true });
expect(fanavaranClaimReferences({
status: ClaimCaseStatus.COMPLETED,
fanavaranSync: { expertise: { status: "failed" } },
})).toBeUndefined();
});
it("returns undefined before the claim is completed", () => {
expect(
fanavaranClaimReferences({
@@ -5,6 +5,8 @@ import {
} from "./fanavaran-attachment-status";
export type FanavaranClaimReferences = {
/** Final expertise has been accepted; earlier stage codes alone are insufficient. */
submissionCompleted?: boolean;
claimId?: number;
claimNo?: number;
dmgCaseId?: number;
@@ -21,7 +23,8 @@ export type FanavaranClaimReferences = {
};
/**
* Claim reference codes appear on COMPLETED. Upload receipts/status are visible earlier.
* Claim reference codes appear on COMPLETED. Upload receipts and final-submission
* acceptance are visible independently of local workflow status.
*/
export function fanavaranClaimReferences(claim: {
status?: string;
@@ -33,9 +36,16 @@ export function fanavaranClaimReferences(claim: {
baseClaim?: FanavaranReferenceStage | null;
damageCase?: FanavaranReferenceStage | null;
attachments?: FanavaranAttachmentStage | null;
expertise?: { status?: string; expertiseId?: number | null } | null;
} | null;
}): FanavaranClaimReferences | undefined {
const refs: FanavaranClaimReferences = {};
if (
claim.expertiseId != null ||
claim.fanavaranSync?.expertise?.status === "success"
) {
refs.submissionCompleted = true;
}
const attachments = fanavaranAttachmentStatus(
claim.fanavaranSync?.attachments,
);
@@ -44,7 +54,7 @@ export function fanavaranClaimReferences(claim: {
refs.attachments = attachments;
}
if (claim.status !== ClaimCaseStatus.COMPLETED) {
return attachments ? refs : undefined;
return Object.keys(refs).length ? refs : undefined;
}
if (claim.claimId != null) refs.claimId = claim.claimId;
if (claim.claimNo != null) refs.claimNo = claim.claimNo;