forked from Yara724/api
fanavaran expert codes
This commit is contained in:
@@ -355,6 +355,12 @@ interface FanavaranAttachmentCandidate {
|
||||
submittedFileId?: unknown;
|
||||
}
|
||||
|
||||
interface FanavaranClaimExpertContext {
|
||||
initiatedByFieldExpertId?: unknown;
|
||||
evaluation?: object;
|
||||
workflow?: { assignedForReviewBy?: { actorId?: unknown } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns today's Jalali date as a packed integer YYYYMMDD for cheap comparison.
|
||||
* Uses the browser/Node `fa-IR` locale which is available everywhere Node runs.
|
||||
@@ -3457,7 +3463,7 @@ export class ClaimRequestManagementService {
|
||||
decision?: { decidedByExpertId?: unknown };
|
||||
};
|
||||
},
|
||||
claimCase?: { initiatedByFieldExpertId?: unknown } | null,
|
||||
claimCase?: FanavaranClaimExpertContext | null,
|
||||
): Promise<{
|
||||
claimExpertId: number | null;
|
||||
code: string | null;
|
||||
@@ -3507,14 +3513,22 @@ export class ClaimRequestManagementService {
|
||||
};
|
||||
}
|
||||
|
||||
// User-created claims may have no blame expert. Their damage reviewer is
|
||||
// still staff attached to this file and can supply the stage-1 product code.
|
||||
const candidateIds = [
|
||||
...new Set(
|
||||
[
|
||||
blame.initiatedByFieldExpertId,
|
||||
blame.expert?.assignedExpertId,
|
||||
blame.expert?.decision?.decidedByExpertId,
|
||||
claimCase?.initiatedByFieldExpertId,
|
||||
this.fanavaranDamageReplyActorId(claimCase),
|
||||
claimCase?.workflow?.assignedForReviewBy?.actorId,
|
||||
]
|
||||
.filter((value) => value != null && String(value).trim() !== "")
|
||||
.map((value) => String(value));
|
||||
.map((value) => String(value)),
|
||||
),
|
||||
];
|
||||
|
||||
const missingOnStaff: string[] = [];
|
||||
for (const staffId of candidateIds) {
|
||||
@@ -3543,7 +3557,7 @@ export class ClaimRequestManagementService {
|
||||
code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
||||
message:
|
||||
candidateIds.length === 0
|
||||
? `ClaimExpertId unresolved: this claim/blame has no assigned staff id (checked initiatedByFieldExpertId, expert.assignedExpertId, expert.decision.decidedByExpertId). Codes like ThirdPartyClaimExpertId=5507 on some other staff profile are ignored until that staff is assigned to this file.`
|
||||
? `ClaimExpertId unresolved: this claim/blame has no assigned staff id (checked initiatedByFieldExpertId, expert.assignedExpertId, expert.decision.decidedByExpertId, evaluation.damageExpertReplyFinal/damageExpertReply.actorDetail.actorId, workflow.assignedForReviewBy.actorId). Assign staff with ${fieldName} to this file.`
|
||||
: `ClaimExpertId unresolved: checked assigned staff [${missingOnStaff.join("; ")}]. Your ${fieldName} must be on THAT assigned staff document, not a different user.`,
|
||||
candidatesTried: candidateIds,
|
||||
};
|
||||
@@ -3564,7 +3578,7 @@ export class ClaimRequestManagementService {
|
||||
decision?: { decidedByExpertId?: unknown };
|
||||
};
|
||||
},
|
||||
claimCase?: { initiatedByFieldExpertId?: unknown } | null,
|
||||
claimCase?: FanavaranClaimExpertContext | null,
|
||||
options?: { required?: boolean },
|
||||
): Promise<number | null> {
|
||||
const resolved = await this.tryResolveFanavaranBaseClaimExpertId(
|
||||
@@ -3581,6 +3595,26 @@ export class ClaimRequestManagementService {
|
||||
});
|
||||
}
|
||||
|
||||
private fanavaranDamageReplyActorId(
|
||||
claimCase?: { evaluation?: object } | null,
|
||||
): unknown {
|
||||
const evaluation = claimCase?.evaluation as
|
||||
| {
|
||||
damageExpertReplyFinal?: { actorDetail?: { actorId?: unknown } };
|
||||
damageExpertReply?: { actorDetail?: { actorId?: unknown } };
|
||||
}
|
||||
| undefined;
|
||||
const active = getActiveV2ExpertReply({
|
||||
evaluation: claimCase?.evaluation as Record<string, unknown> | undefined,
|
||||
});
|
||||
return (
|
||||
(active?.reply as { actorDetail?: { actorId?: unknown } } | undefined)
|
||||
?.actorDetail?.actorId ??
|
||||
evaluation?.damageExpertReplyFinal?.actorDetail?.actorId ??
|
||||
evaluation?.damageExpertReply?.actorDetail?.actorId
|
||||
);
|
||||
}
|
||||
|
||||
private async tryResolveFanavaranExpertiseClaimExpertId(
|
||||
blame: {
|
||||
isMadeByFileMaker?: boolean;
|
||||
@@ -3647,20 +3681,7 @@ export class ClaimRequestManagementService {
|
||||
};
|
||||
}
|
||||
|
||||
const evaluation = claimCase?.evaluation as
|
||||
| {
|
||||
damageExpertReplyFinal?: { actorDetail?: { actorId?: unknown } };
|
||||
damageExpertReply?: { actorDetail?: { actorId?: unknown } };
|
||||
}
|
||||
| undefined;
|
||||
const active = getActiveV2ExpertReply(
|
||||
claimCase as unknown as { evaluation?: Record<string, unknown> },
|
||||
);
|
||||
const actorId =
|
||||
(active?.reply as { actorDetail?: { actorId?: unknown } } | undefined)
|
||||
?.actorDetail?.actorId ??
|
||||
evaluation?.damageExpertReplyFinal?.actorDetail?.actorId ??
|
||||
evaluation?.damageExpertReply?.actorDetail?.actorId;
|
||||
const actorId = this.fanavaranDamageReplyActorId(claimCase);
|
||||
if (actorId == null || String(actorId).trim() === "") {
|
||||
return {
|
||||
claimExpertId: null,
|
||||
|
||||
@@ -31,6 +31,32 @@ function serviceWithStaff(stubs: {
|
||||
}
|
||||
|
||||
describe("Fanavaran assigned ClaimExpertId resolution", () => {
|
||||
it("resolves a user-created base claim from its damage-expert reply actor", async () => {
|
||||
const management = serviceWithStaff({
|
||||
damageExpert: {
|
||||
ThirdPartyClaimExpertId: "5507",
|
||||
ThirdPartyExpertiseClaim: "5510",
|
||||
},
|
||||
});
|
||||
const resolved = await (
|
||||
management as any
|
||||
).tryResolveFanavaranBaseClaimExpertId(
|
||||
{ type: BlameRequestType.THIRD_PARTY },
|
||||
{
|
||||
evaluation: {
|
||||
damageExpertReply: {
|
||||
actorDetail: { actorId: "6af036ab0222c1322767ce19" },
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(resolved).toMatchObject({
|
||||
claimExpertId: 5507,
|
||||
code: null,
|
||||
candidatesTried: ["6af036ab0222c1322767ce19"],
|
||||
});
|
||||
});
|
||||
|
||||
it("reads GEN.03 ClaimExpertId from assigned blame expert DB codes", async () => {
|
||||
const management = serviceWithStaff({
|
||||
expert: { ThirdPartyClaimExpertId: "154" },
|
||||
@@ -43,6 +69,106 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => {
|
||||
).resolves.toBe(154);
|
||||
});
|
||||
|
||||
it.each(["blame", "claim"])(
|
||||
"reads V2/V3 stage-1 codes from the %s field-expert initiator",
|
||||
async (source) => {
|
||||
const management = serviceWithStaff({
|
||||
fieldExpert: { ThirdPartyClaimExpertId: "154" },
|
||||
});
|
||||
(management as any).damageExpertDbService.findById.mockImplementation(
|
||||
async (id: string) =>
|
||||
id === "dmg-1" ? { ThirdPartyClaimExpertId: "5507" } : null,
|
||||
);
|
||||
await expect(
|
||||
(management as any).resolveFanavaranBaseClaimExpertId(
|
||||
{
|
||||
type: BlameRequestType.THIRD_PARTY,
|
||||
...(source === "blame" && { initiatedByFieldExpertId: "field-1" }),
|
||||
},
|
||||
{
|
||||
...(source === "claim" && { initiatedByFieldExpertId: "field-1" }),
|
||||
evaluation: {
|
||||
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
||||
},
|
||||
},
|
||||
),
|
||||
).resolves.toBe(154);
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves the CAR_BODY stage-1 code from the final review actor", async () => {
|
||||
const management = serviceWithStaff({
|
||||
damageExpert: {
|
||||
CarBodyClaimExpertId: "5508",
|
||||
CarBodyExpertiseClaim: "5509",
|
||||
},
|
||||
});
|
||||
const resolved = await (
|
||||
management as any
|
||||
).tryResolveFanavaranBaseClaimExpertId(
|
||||
{ type: BlameRequestType.CAR_BODY },
|
||||
{
|
||||
evaluation: {
|
||||
damageExpertReply: { actorDetail: { actorId: "initial-reviewer" } },
|
||||
damageExpertReplyFinal: {
|
||||
actorDetail: { actorId: "final-reviewer" },
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(resolved.claimExpertId).toBe(5508);
|
||||
expect(
|
||||
(management as any).damageExpertDbService.findById,
|
||||
).toHaveBeenCalledWith("final-reviewer");
|
||||
});
|
||||
|
||||
it("resolves stage-1 from persistent claim assignment before a reply exists", async () => {
|
||||
const management = serviceWithStaff({
|
||||
damageExpert: { ThirdPartyClaimExpertId: "5507" },
|
||||
});
|
||||
await expect(
|
||||
(management as any).resolveFanavaranBaseClaimExpertId(
|
||||
{ type: BlameRequestType.THIRD_PARTY },
|
||||
{ workflow: { assignedForReviewBy: { actorId: "dmg-1" } } },
|
||||
),
|
||||
).resolves.toBe(5507);
|
||||
});
|
||||
|
||||
it("does not treat a temporary workflow lock as review assignment", async () => {
|
||||
const management = serviceWithStaff({
|
||||
damageExpert: { ThirdPartyClaimExpertId: "5507" },
|
||||
});
|
||||
const resolved = await (
|
||||
management as any
|
||||
).tryResolveFanavaranBaseClaimExpertId(
|
||||
{ type: BlameRequestType.THIRD_PARTY },
|
||||
{ workflow: { lockedBy: { actorId: "someone-else" } } },
|
||||
);
|
||||
expect(resolved.claimExpertId).toBeNull();
|
||||
expect(
|
||||
(management as any).damageExpertDbService.findById,
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports an attached review actor whose stage-1 code is missing", async () => {
|
||||
const management = serviceWithStaff({
|
||||
damageExpert: { ThirdPartyExpertiseClaim: "5510" },
|
||||
});
|
||||
const resolved = await (
|
||||
management as any
|
||||
).tryResolveFanavaranBaseClaimExpertId(
|
||||
{ type: BlameRequestType.THIRD_PARTY },
|
||||
{
|
||||
evaluation: {
|
||||
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(resolved.claimExpertId).toBeNull();
|
||||
expect(resolved.candidatesTried).toEqual(["dmg-1"]);
|
||||
expect(resolved.message).toContain("ThirdPartyClaimExpertId=empty");
|
||||
});
|
||||
|
||||
it("reads GEN.03 ClaimExpertId from FileMaker on V4/V5", async () => {
|
||||
const management = serviceWithStaff({
|
||||
fileMaker: {
|
||||
@@ -51,11 +177,18 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => {
|
||||
},
|
||||
});
|
||||
await expect(
|
||||
(management as any).resolveFanavaranBaseClaimExpertId({
|
||||
(management as any).resolveFanavaranBaseClaimExpertId(
|
||||
{
|
||||
type: BlameRequestType.THIRD_PARTY,
|
||||
isMadeByFileMaker: true,
|
||||
initiatedByFieldExpertId: "fm-1",
|
||||
}),
|
||||
},
|
||||
{
|
||||
evaluation: {
|
||||
damageExpertReply: { actorDetail: { actorId: "dmg-1" } },
|
||||
},
|
||||
},
|
||||
),
|
||||
).resolves.toBe(5347);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user