From f49e6b704bbc781bd83959ff77f0810c974f5eaf Mon Sep 17 00:00:00 2001 From: "s.hajizadeh" Date: Mon, 9 Nov 2026 17:29:35 +0330 Subject: [PATCH] expert codes --- .../claim-request-management.service.ts | 460 +++++++++++++----- .../fanavaran-assigned-expert-ids.spec.ts | 25 + src/common/errors/persian-errors.ts | 10 + .../fanavaran-stage-fields.spec.ts | 20 +- src/fanavaran/fanavaran.controller.ts | 3 +- 5 files changed, 396 insertions(+), 122 deletions(-) diff --git a/src/claim-request-management/claim-request-management.service.ts b/src/claim-request-management/claim-request-management.service.ts index 4d6a027..65c66b5 100644 --- a/src/claim-request-management/claim-request-management.service.ts +++ b/src/claim-request-management/claim-request-management.service.ts @@ -32,8 +32,6 @@ import { BranchDbService } from "src/client/entities/db-service/branch.db.servic import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto"; import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto"; import { - assertFileMakerCanCreateBlameType, - assertFileReviewerCanReviewBlameType, resolveFileMakerStageOneExpertId, resolveFileReviewerExpertiseExpertId, type StaffFanavaranExpertiseCodes, @@ -3394,6 +3392,35 @@ export class ClaimRequestManagementService { return rest; } + private staffFanavaranCodesFromDoc( + doc: unknown, + ): (StaffFanavaranStageOneCodes & StaffFanavaranExpertiseCodes) | null { + if (!doc || typeof doc !== "object") return null; + const plain = + typeof (doc as { toObject?: () => Record }).toObject === + "function" + ? (doc as { toObject: () => Record }).toObject() + : (doc as Record); + return { + ThirdPartyClaimExpertId: + plain.ThirdPartyClaimExpertId != null + ? String(plain.ThirdPartyClaimExpertId) + : undefined, + CarBodyClaimExpertId: + plain.CarBodyClaimExpertId != null + ? String(plain.CarBodyClaimExpertId) + : undefined, + ThirdPartyExpertiseClaim: + plain.ThirdPartyExpertiseClaim != null + ? String(plain.ThirdPartyExpertiseClaim) + : undefined, + CarBodyExpertiseClaim: + plain.CarBodyExpertiseClaim != null + ? String(plain.CarBodyExpertiseClaim) + : undefined, + }; + } + private async findStaffDocumentById( staffId: string, ): Promise< @@ -3401,22 +3428,130 @@ export class ClaimRequestManagementService { | null > { const loaders = [ - () => this.fileMakerDbService.findById(staffId), - () => this.fileReviewerDbService.findById(staffId), - () => this.fieldExpertDbService.findById(staffId), () => this.expertDbService.findById(staffId), () => this.damageExpertDbService.findById(staffId), + () => this.fieldExpertDbService.findById(staffId), + () => this.fileMakerDbService.findById(staffId), + () => this.fileReviewerDbService.findById(staffId), ]; for (const load of loaders) { - const doc = await load(); - if (doc) return doc as StaffFanavaranStageOneCodes & StaffFanavaranExpertiseCodes; + try { + const doc = await load(); + const codes = this.staffFanavaranCodesFromDoc(doc); + if (codes) return codes; + } catch { + // invalid ObjectId / cast errors — try next collection + } } return null; } + private async tryResolveFanavaranBaseClaimExpertId( + blame: { + isMadeByFileMaker?: boolean; + type?: BlameRequestType; + initiatedByFieldExpertId?: unknown; + assignedFileReviewerId?: unknown; + expert?: { + assignedExpertId?: unknown; + decision?: { decidedByExpertId?: unknown }; + }; + }, + claimCase?: { initiatedByFieldExpertId?: unknown } | null, + ): Promise<{ + claimExpertId: number | null; + code: string | null; + message: string | null; + candidatesTried: string[]; + }> { + const fieldName = + blame?.type === BlameRequestType.CAR_BODY + ? "CarBodyClaimExpertId" + : "ThirdPartyClaimExpertId"; + + if (blame?.type == null) { + return { + claimExpertId: null, + code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING", + message: + "ClaimExpertId unresolved: blame.type is missing, so the product line expert code cannot be chosen.", + candidatesTried: [], + }; + } + + if (blame.isMadeByFileMaker && blame.initiatedByFieldExpertId) { + const fileMakerId = String(blame.initiatedByFieldExpertId); + const fileMaker = await this.fileMakerDbService.findById(fileMakerId); + if (!fileMaker) { + return { + claimExpertId: null, + code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING", + message: `ClaimExpertId unresolved: FileMaker ${fileMakerId} was not found.`, + candidatesTried: [fileMakerId], + }; + } + const id = resolveFileMakerStageOneExpertId(fileMaker, blame.type); + if (id == null) { + return { + claimExpertId: null, + code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING", + message: `ClaimExpertId unresolved: FileMaker ${fileMakerId} has empty ${fieldName}.`, + candidatesTried: [fileMakerId], + }; + } + return { + claimExpertId: id, + code: null, + message: null, + candidatesTried: [fileMakerId], + }; + } + + const candidateIds = [ + blame.initiatedByFieldExpertId, + blame.expert?.assignedExpertId, + blame.expert?.decision?.decidedByExpertId, + claimCase?.initiatedByFieldExpertId, + ] + .filter((value) => value != null && String(value).trim() !== "") + .map((value) => String(value)); + + const missingOnStaff: string[] = []; + for (const staffId of candidateIds) { + const staff = await this.findStaffDocumentById(staffId); + if (!staff) { + missingOnStaff.push(`${staffId} (staff not found in expert/damage/field/fileMaker/fileReviewer)`); + continue; + } + const rawValue = (staff as Record)[fieldName]; + const id = resolveFileMakerStageOneExpertId(staff, blame.type); + if (id != null) { + return { + claimExpertId: id, + code: null, + message: null, + candidatesTried: candidateIds, + }; + } + missingOnStaff.push( + `${staffId} (${fieldName}=${rawValue == null || rawValue === "" ? "empty" : JSON.stringify(rawValue)})`, + ); + } + + return { + claimExpertId: null, + 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: checked assigned staff [${missingOnStaff.join("; ")}]. Your ${fieldName} must be on THAT assigned staff document, not a different user.`, + candidatesTried: candidateIds, + }; + } + /** * GEN.03 ClaimExpertId from the staff assigned to this file (never tenant defaults). - * V4/V5 FileMaker → FileMaker codes; otherwise field/blame/claim expert assignment. + * Preview may pass `{ required: false }` to keep building the payload with null. */ private async resolveFanavaranBaseClaimExpertId( blame: { @@ -3430,109 +3565,86 @@ export class ClaimRequestManagementService { }; }, claimCase?: { initiatedByFieldExpertId?: unknown } | null, - ): Promise { - if (blame?.type == null) { - throw new BadRequestException({ - code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING", - message: - "Cannot resolve Fanavaran ClaimExpertId: blame product type is missing.", - }); - } - - if (blame.isMadeByFileMaker && blame.initiatedByFieldExpertId) { - const fileMaker = await this.fileMakerDbService.findById( - String(blame.initiatedByFieldExpertId), - ); - if (!fileMaker) { - throw new BadRequestException({ - code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING", - message: - "This FileMaker file cannot be submitted to Fanavaran: FileMaker profile was not found.", - }); - } - assertFileMakerCanCreateBlameType(fileMaker, blame.type); - const id = resolveFileMakerStageOneExpertId(fileMaker, blame.type); - if (id == null) { - throw new BadRequestException({ - code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING", - message: - "This FileMaker file cannot be submitted to Fanavaran: stage-1 claim expert id is missing for this product line.", - }); - } - return id; - } - - const candidateIds = [ - blame.initiatedByFieldExpertId, - blame.expert?.assignedExpertId, - blame.expert?.decision?.decidedByExpertId, - claimCase?.initiatedByFieldExpertId, - ] - .filter((value) => value != null && String(value).trim() !== "") - .map((value) => String(value)); - - for (const staffId of candidateIds) { - const staff = await this.findStaffDocumentById(staffId); - if (!staff) continue; - const id = resolveFileMakerStageOneExpertId(staff, blame.type); - if (id != null) return id; - } - + options?: { required?: boolean }, + ): Promise { + const resolved = await this.tryResolveFanavaranBaseClaimExpertId( + blame, + claimCase, + ); + if (resolved.claimExpertId != null) return resolved.claimExpertId; + if (options?.required === false) return null; throw new BadRequestException({ - code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING", + code: resolved.code ?? "FANAVARAN_CLAIM_EXPERT_ID_MISSING", message: - "Fanavaran ClaimExpertId is missing on the assigned expert profile for this product line. Set ThirdPartyClaimExpertId or CarBodyClaimExpertId on the assigned staff.", + resolved.message ?? + "ClaimExpertId unresolved on the assigned expert profile.", }); } - /** - * GEN.08 / GEN.06 ClaimExpertId from the assessor assigned to this file (never tenant defaults). - * V4/V5 FileMaker → FileReviewer; otherwise the damage-expert (or other staff) who priced the claim. - */ - private async resolveFanavaranExpertiseClaimExpertId( + private async tryResolveFanavaranExpertiseClaimExpertId( blame: { isMadeByFileMaker?: boolean; type?: BlameRequestType; assignedFileReviewerId?: unknown; }, claimCase: { evaluation?: Record } | null | undefined, - ): Promise { + ): Promise<{ + claimExpertId: number | null; + code: string | null; + message: string | null; + candidatesTried: string[]; + }> { + const fieldName = + blame?.type === BlameRequestType.CAR_BODY + ? "CarBodyExpertiseClaim" + : "ThirdPartyExpertiseClaim"; + if (blame?.type == null) { - throw new BadRequestException({ + return { + claimExpertId: null, code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", message: - "Cannot resolve Fanavaran expertise ClaimExpertId: blame product type is missing.", - }); + "Expertise ClaimExpertId unresolved: blame.type is missing.", + candidatesTried: [], + }; } if (blame.isMadeByFileMaker) { if (!blame.assignedFileReviewerId) { - throw new BadRequestException({ + return { + claimExpertId: null, code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING", message: - "Fanavaran expertise cannot be submitted: assign a FileReviewer with an expertise claim expert id for this product line.", - }); + "Expertise ClaimExpertId unresolved: no assignedFileReviewerId on this FileMaker file.", + candidatesTried: [], + }; } - const fileReviewer = await this.fileReviewerDbService.findById( - String(blame.assignedFileReviewerId), - ); + const fileReviewerId = String(blame.assignedFileReviewerId); + const fileReviewer = + await this.fileReviewerDbService.findById(fileReviewerId); if (!fileReviewer) { - throw new BadRequestException({ + return { + claimExpertId: null, code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING", - message: - "Fanavaran expertise cannot be submitted: FileReviewer profile was not found.", - }); + message: `Expertise ClaimExpertId unresolved: FileReviewer ${fileReviewerId} was not found.`, + candidatesTried: [fileReviewerId], + }; } - assertFileReviewerCanReviewBlameType(fileReviewer, blame.type); const id = resolveFileReviewerExpertiseExpertId(fileReviewer, blame.type); if (id == null) { - throw new BadRequestException({ + return { + claimExpertId: null, code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING", - message: - "Fanavaran expertise cannot be submitted: assign a FileReviewer with an expertise claim expert id for this product line.", - }); + message: `Expertise ClaimExpertId unresolved: FileReviewer ${fileReviewerId} has empty ${fieldName}.`, + candidatesTried: [fileReviewerId], + }; } - return id; + return { + claimExpertId: id, + code: null, + message: null, + candidatesTried: [fileReviewerId], + }; } const evaluation = claimCase?.evaluation as @@ -3550,25 +3662,67 @@ export class ClaimRequestManagementService { evaluation?.damageExpertReplyFinal?.actorDetail?.actorId ?? evaluation?.damageExpertReply?.actorDetail?.actorId; if (actorId == null || String(actorId).trim() === "") { - throw new BadRequestException({ + return { + claimExpertId: null, code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", message: - "Fanavaran expertise ClaimExpertId cannot be resolved: no damage-expert reply actor is assigned on this claim.", - }); + "Expertise ClaimExpertId unresolved: no damage-expert reply actorDetail.actorId on this claim.", + candidatesTried: [], + }; } - const staff = await this.findStaffDocumentById(String(actorId)); - const id = staff - ? resolveFileReviewerExpertiseExpertId(staff, blame.type) - : null; - if (id == null) { - throw new BadRequestException({ + const staffId = String(actorId); + const staff = await this.findStaffDocumentById(staffId); + if (!staff) { + return { + claimExpertId: null, code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", - message: - "Fanavaran ClaimExpertId is missing on the assigned assessor profile for this product line. Set ThirdPartyExpertiseClaim or CarBodyExpertiseClaim on the assigned staff.", - }); + message: `Expertise ClaimExpertId unresolved: staff ${staffId} was not found.`, + candidatesTried: [staffId], + }; } - return id; + const id = resolveFileReviewerExpertiseExpertId(staff, blame.type); + if (id == null) { + return { + claimExpertId: null, + code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", + message: `Expertise ClaimExpertId unresolved: staff ${staffId} has empty ${fieldName}.`, + candidatesTried: [staffId], + }; + } + return { + claimExpertId: id, + code: null, + message: null, + candidatesTried: [staffId], + }; + } + + /** + * GEN.08 / GEN.06 ClaimExpertId from the assessor assigned to this file (never tenant defaults). + * Preview may pass `{ required: false }` to keep building the payload with null. + */ + private async resolveFanavaranExpertiseClaimExpertId( + blame: { + isMadeByFileMaker?: boolean; + type?: BlameRequestType; + assignedFileReviewerId?: unknown; + }, + claimCase: { evaluation?: Record } | null | undefined, + options?: { required?: boolean }, + ): Promise { + const resolved = await this.tryResolveFanavaranExpertiseClaimExpertId( + blame, + claimCase, + ); + if (resolved.claimExpertId != null) return resolved.claimExpertId; + if (options?.required === false) return null; + throw new BadRequestException({ + code: resolved.code ?? "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", + message: + resolved.message ?? + "Expertise ClaimExpertId unresolved on the assigned assessor profile.", + }); } /** @deprecated Use resolveFanavaranBaseClaimExpertId / resolveFanavaranExpertiseClaimExpertId */ @@ -4190,6 +4344,12 @@ export class ClaimRequestManagementService { resolvePolicy?: boolean; /** When true (submit), missing PolicyId throws. Preview keeps payload even if inquiry fails. */ requirePolicyId?: boolean; + /** + * When false (HTTP preview), missing staff ClaimExpertId stays null and is + * reported in previewWarnings instead of throwing. + * Submit keeps the default (required). + */ + requireClaimExpertId?: boolean; auditSession?: FanavaranAuditSession; /** Persist built payload onto fanavaranSync.baseClaim.lastPayload (default true). */ persistPayload?: boolean; @@ -4209,7 +4369,14 @@ export class ClaimRequestManagementService { const forceRefreshPolicy = options?.forceRefreshPolicy === true; const forceRefreshUsedId = options?.forceRefreshUsedId === true; const requirePolicyId = options?.requirePolicyId === true; + const requireClaimExpertId = options?.requireClaimExpertId !== false; const persistPayload = options?.persistPayload !== false; + const previewWarnings: Array<{ + code: string; + message: string; + field: string; + candidatesTried?: string[]; + }> = []; const auditSession = options?.auditSession ?? ({ @@ -4583,10 +4750,34 @@ export class ClaimRequestManagementService { } } - payload.ClaimExpertId = await this.resolveFanavaranBaseClaimExpertId( - blameCase, - claimCase, - ); + const claimExpertResolution = + await this.tryResolveFanavaranBaseClaimExpertId(blameCase, claimCase); + payload.ClaimExpertId = claimExpertResolution.claimExpertId; + (debug as any).steps.claimExpertIdResolved = + claimExpertResolution.claimExpertId != null; + (debug as any).values.claimExpertId = + claimExpertResolution.claimExpertId; + (debug as any).values.claimExpertIdCandidatesTried = + claimExpertResolution.candidatesTried; + if (claimExpertResolution.claimExpertId == null) { + const warning = { + code: + claimExpertResolution.code ?? "FANAVARAN_CLAIM_EXPERT_ID_MISSING", + message: + claimExpertResolution.message ?? + "ClaimExpertId unresolved on the assigned expert profile.", + field: "ClaimExpertId", + candidatesTried: claimExpertResolution.candidatesTried, + }; + previewWarnings.push(warning); + (debug as any).values.claimExpertIdWarning = warning.message; + if (requireClaimExpertId) { + throw new BadRequestException({ + code: warning.code, + message: warning.message, + }); + } + } if (persistPayload) { await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, { @@ -4617,6 +4808,14 @@ export class ClaimRequestManagementService { clientKey, payload, debug, + previewWarnings, + }; + } + + if (previewWarnings.length > 0) { + return { + payload, + previewWarnings, }; } @@ -5557,6 +5756,8 @@ export class ClaimRequestManagementService { private async buildFanavaranExpertisePayload(input: { claimCase: any; clientKey: FanavaranClientKey; + /** Preview keeps null ClaimExpertId; submit requires it. Default true. */ + requireClaimExpertId?: boolean; }): Promise<{ payload: Record; warnings: string[]; @@ -5564,6 +5765,7 @@ export class ClaimRequestManagementService { }> { const profile = getFanavaranClientProfile(input.clientKey); const active = getActiveV2ExpertReply(input.claimCase as any); + const requireClaimExpertId = input.requireClaimExpertId !== false; const blameForExpertIds = input.claimCase?.blameRequestId ? await this.blameRequestDbService.findById( @@ -5572,22 +5774,42 @@ export class ClaimRequestManagementService { : null; // GEN.08 / GEN.06 ClaimExpertId always from assigned assessor staff profile. - if (!blameForExpertIds) { - throw new BadRequestException({ - code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", - message: - "Fanavaran expertise cannot be submitted: linked blame case was not found.", - }); - } - const claimExpertId = await this.resolveFanavaranExpertiseClaimExpertId( - blameForExpertIds as { - isMadeByFileMaker?: boolean; - type?: BlameRequestType; - assignedFileReviewerId?: unknown; - }, - input.claimCase, - ); const warnings: string[] = []; + let claimExpertId: number | null = null; + if (!blameForExpertIds) { + const message = + "Expertise ClaimExpertId unresolved: linked blame case was not found."; + if (requireClaimExpertId) { + throw new BadRequestException({ + code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", + message, + }); + } + warnings.push(message); + } else { + const resolved = await this.tryResolveFanavaranExpertiseClaimExpertId( + blameForExpertIds as { + isMadeByFileMaker?: boolean; + type?: BlameRequestType; + assignedFileReviewerId?: unknown; + }, + input.claimCase, + ); + claimExpertId = resolved.claimExpertId; + if (resolved.claimExpertId == null) { + const message = + resolved.message ?? + "Expertise ClaimExpertId unresolved on the assigned assessor profile."; + if (requireClaimExpertId) { + throw new BadRequestException({ + code: + resolved.code ?? "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING", + message, + }); + } + warnings.push(message); + } + } if (!active?.parts?.length) { warnings.push("No active damage expert reply with priced parts exists."); @@ -5709,7 +5931,11 @@ export class ClaimRequestManagementService { if (!claimCase) throw new NotFoundException("Claim case not found"); const { payload, warnings, replyKey } = - await this.buildFanavaranExpertisePayload({ claimCase, clientKey }); + await this.buildFanavaranExpertisePayload({ + claimCase, + clientKey, + requireClaimExpertId: false, + }); await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, { $set: { @@ -5728,7 +5954,7 @@ export class ClaimRequestManagementService { submitUrl: claimCase.claimId ? `${await this.fanavaranClaimsUrlForClaim(claimCaseId)}/${claimCase.claimId}/expertise` : null, - ready: warnings.length === 0, + ready: warnings.length === 0 && payload.ClaimExpertId != null, warnings: Array.from(new Set(warnings)), payload, }; diff --git a/src/claim-request-management/fanavaran-assigned-expert-ids.spec.ts b/src/claim-request-management/fanavaran-assigned-expert-ids.spec.ts index 75dd6bd..91e6cbe 100644 --- a/src/claim-request-management/fanavaran-assigned-expert-ids.spec.ts +++ b/src/claim-request-management/fanavaran-assigned-expert-ids.spec.ts @@ -104,4 +104,29 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => { }), ).rejects.toBeInstanceOf(BadRequestException); }); + + it("preview soft-resolve returns null plus a concrete warning instead of throwing", async () => { + const management = serviceWithStaff({}); + await expect( + (management as any).resolveFanavaranBaseClaimExpertId( + { + type: BlameRequestType.THIRD_PARTY, + expert: { assignedExpertId: "missing" }, + }, + null, + { required: false }, + ), + ).resolves.toBeNull(); + + const soft = await (management as any).tryResolveFanavaranBaseClaimExpertId( + { + type: BlameRequestType.THIRD_PARTY, + expert: { assignedExpertId: "missing" }, + }, + ); + expect(soft.claimExpertId).toBeNull(); + expect(soft.code).toBe("FANAVARAN_CLAIM_EXPERT_ID_MISSING"); + expect(soft.message).toMatch(/ThirdPartyClaimExpertId/); + expect(soft.candidatesTried).toEqual(["missing"]); + }); }); diff --git a/src/common/errors/persian-errors.ts b/src/common/errors/persian-errors.ts index 0e3702c..76a5119 100644 --- a/src/common/errors/persian-errors.ts +++ b/src/common/errors/persian-errors.ts @@ -561,6 +561,16 @@ export function localizeErrorMessage( return "این عملیات در مرحله فعلی پرونده امکان‌پذیر نیست. پرونده را دوباره باز کنید و مرحله جاری را بررسی کنید."; if (/file.*required|video.*required|image.*required/i.test(message)) return "فایل لازم برای این مرحله را بارگذاری کنید."; + if ( + /ClaimExpertId unresolved|ThirdPartyClaimExpertId|CarBodyClaimExpertId|ThirdPartyExpertiseClaim|CarBodyExpertiseClaim/i.test( + message, + ) + ) { + if (/Expertise ClaimExpertId|expertise claim expert|FileReviewer/i.test(message)) { + return "کد کارشناس ارزیاب فناوران (ClaimExpertId مرحله کارشناسی) روی پروفایل کارشناس اختصاص‌یافته تنظیم نشده است. ThirdPartyExpertiseClaim یا CarBodyExpertiseClaim را در مدیریت کارکنان تنظیم کنید."; + } + return "کد کارشناس مسئول پرونده فناوران (ClaimExpertId) روی پروفایل کارشناس اختصاص‌یافته تنظیم نشده است. ThirdPartyClaimExpertId یا CarBodyClaimExpertId را در مدیریت کارکنان تنظیم کنید."; + } if ( /fanavaran.*(?:missing|required|failed)|policyid.*required/i.test(message) ) diff --git a/src/expert-claim/fanavaran-stage-fields.spec.ts b/src/expert-claim/fanavaran-stage-fields.spec.ts index 1f0923d..81e5c81 100644 --- a/src/expert-claim/fanavaran-stage-fields.spec.ts +++ b/src/expert-claim/fanavaran-stage-fields.spec.ts @@ -152,9 +152,14 @@ describe("Expert Fanavaran stage fields", () => { management.resolveAccidentVehicleUsedFromApis = jest .fn() .mockResolvedValue({ usedId: 1 }); - management.resolveFanavaranBaseClaimExpertId = jest + management.tryResolveFanavaranBaseClaimExpertId = jest .fn() - .mockResolvedValue(154); + .mockResolvedValue({ + claimExpertId: 154, + code: null, + message: null, + candidatesTried: ["expert-1"], + }); management.enrichCarBodyHullBaseClaimPayload = jest .fn() .mockImplementation(async ({ payload }) => { @@ -164,6 +169,7 @@ describe("Expert Fanavaran stage fields", () => { const payload = await management.previewFanavaranSubmitV2(id, clientKey, { persistPayload: false, forceRefreshPolicy: false, + requireClaimExpertId: false, }); expect(payload.ClaimExpertId).toBe(154); expect(payload).toMatchObject({ @@ -234,15 +240,21 @@ describe("Expert Fanavaran stage fields", () => { management.blameRequestDbService = { findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }), }; - management.resolveFanavaranExpertiseClaimExpertId = jest + management.tryResolveFanavaranExpertiseClaimExpertId = jest .fn() - .mockResolvedValue(29); + .mockResolvedValue({ + claimExpertId: 29, + code: null, + message: null, + candidatesTried: ["dmg-1"], + }); management.resolveFanavaranClaimProduct = jest .fn() .mockResolvedValue("third-party"); const result = await management.buildFanavaranExpertisePayload({ claimCase: claim, clientKey: "parsian", + requireClaimExpertId: false, }); expect(result.payload).toMatchObject({ InspectionPlaceId: 283, diff --git a/src/fanavaran/fanavaran.controller.ts b/src/fanavaran/fanavaran.controller.ts index e0daa8c..9b9b853 100644 --- a/src/fanavaran/fanavaran.controller.ts +++ b/src/fanavaran/fanavaran.controller.ts @@ -58,7 +58,7 @@ export class FanavaranController { @ApiOperation({ summary: "Preview Fanavaran base claim create payload", description: - "GET has no request body. Always rebuilds GEN.03 from live policy + VIN/vehicle inquiries. Does not reuse fanavaranSync lastPayload / PolicyId / UsedId cache. Auth token is still shared until Asia/Tehran midnight.", + "GET has no request body. Always rebuilds GEN.03 from live policy + VIN/vehicle inquiries. Does not reuse fanavaranSync lastPayload / PolicyId / UsedId cache. Missing staff ClaimExpertId does not fail the preview — it returns ClaimExpertId=null plus previewWarnings with the exact missing field/staff. Auth token is still shared until Asia/Tehran midnight.", }) @ApiParam({ name: "client", @@ -102,6 +102,7 @@ export class FanavaranController { forceRefreshPolicy: true, forceRefreshUsedId: true, requirePolicyId: false, + requireClaimExpertId: false, }, ); }