feat(claims): require optional expert signatures and enrich PDF reports

This commit is contained in:
SepehrYahyaee
2026-11-24 11:23:08 +03:30
parent 297664a9a6
commit 475780f17e
24 changed files with 722 additions and 34 deletions
+11 -1
View File
@@ -28,7 +28,8 @@ function setup() {
evaluation: {},
};
const blame: any = {
type: "CAR_BODY",
type: "THIRD_PARTY",
expert: { decision: { guiltyPartyId: "other-party" } },
parties: [
{
role: "FIRST",
@@ -36,6 +37,7 @@ function setup() {
vehicle: { inquiry: { mapped: { ModelField: "1402" } } },
statement: { accidentDate: "2026-11-23" },
},
{ role: "SECOND", person: { userId: "other-party" } },
],
};
const service = Object.create(ExpertClaimService.prototype) as any;
@@ -66,6 +68,14 @@ function setup() {
}
describe("Fanavaran depreciation review and persistence", () => {
it("does not provide depreciation options or save depreciation for car-body claims", async () => {
const { service, blame, body, id } = setup();
blame.type = "CAR_BODY";
await expect(service.getPriceDropContextV2(id, {})).rejects.toThrow("افت قیمت برای پرونده بیمه بدنه");
await expect(service.upsertPriceDropV2(id, body, {})).rejects.toThrow("افت قیمت برای پرونده بیمه بدنه");
expect(service.claimCaseDbService.findByIdAndUpdate).not.toHaveBeenCalled();
});
it("returns the Fanavaran catalog and age at accident without changing the saved assessment", async () => {
const { service, claim, id } = setup();
claim.evaluation.priceDrop = { total: 123, partLines: [] };
+23
View File
@@ -3976,6 +3976,9 @@ export class ExpertClaimService {
let evaluationForApi: Record<string, unknown> | undefined;
if (enrichedEvaluation) {
if (blameFileContext.blameRequestType === BlameRequestType.CAR_BODY) {
delete enrichedEvaluation.priceDrop;
}
evaluationForApi = {};
// damageExpertReply / damageExpertReplyFinal: include whenever present.
// Previously these were gated on isFactorValidationPending, which hid the
@@ -4072,6 +4075,18 @@ export class ExpertClaimService {
};
}
async assertCanSignFanavaranClaim(id: string, actor: any) {
if (!Types.ObjectId.isValid(id)) throw new BadRequestException("شناسه پرونده معتبر نیست.");
const roles = [
RoleEnum.DAMAGE_EXPERT, RoleEnum.FIELD_EXPERT, RoleEnum.FILE_MAKER,
RoleEnum.FILE_REVIEWER, RoleEnum.REGISTRAR,
];
if (!actor?.sub || !roles.includes(actor.role)) {
throw new ForbiddenException("فقط کارشناس مجاز پرونده می‌تواند آن را امضا کند.");
}
await this.getClaimDetailV2(id, actor);
}
private asFanavaranLookupRows(value: unknown): Array<Record<string, any>> {
if (Array.isArray(value)) return value as Array<Record<string, any>>;
if (value && typeof value === "object") {
@@ -4488,6 +4503,12 @@ export class ExpertClaimService {
return { version: fields.review.version };
}
private assertPriceDropProduct(type: unknown) {
if (type === BlameRequestType.CAR_BODY) {
throw new BadRequestException("افت قیمت برای پرونده بیمه بدنه قابل ثبت نیست.");
}
}
/** V2 price-drop: claim locked by this expert during damage assessment. */
private async assertExpertCanEditClaimDuringReviewV2(
claim: any,
@@ -4539,6 +4560,7 @@ export class ExpertClaimService {
},
);
const blame = blameRows[0] as Record<string, unknown> | undefined;
this.assertPriceDropProduct(blame?.type);
suggestedCarModelYear = resolveVehicleModelYearFromBlame(
claim,
blame as Parameters<typeof resolveVehicleModelYearFromBlame>[1],
@@ -4618,6 +4640,7 @@ export class ExpertClaimService {
select: "type expert.decision.guiltyPartyId parties.role parties.person.userId parties.vehicle parties.statement.accidentDate",
},
);
this.assertPriceDropProduct(blameRows[0]?.type);
carModelYear ??=
resolveVehicleModelYearFromBlame(
claim,