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
+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,