From 91780581733fd5926c3a1b0a00fe4abd4eb97d72 Mon Sep 17 00:00:00 2001 From: "s.hajizadeh" Date: Thu, 12 Nov 2026 17:51:45 +0330 Subject: [PATCH] default sets to 6 when its 1 or its null --- .../fanavaran-hull-lookup-validation.ts | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/claim-request-management/fanavaran-hull-lookup-validation.ts b/src/claim-request-management/fanavaran-hull-lookup-validation.ts index c99d860..b9bd31e 100644 --- a/src/claim-request-management/fanavaran-hull-lookup-validation.ts +++ b/src/claim-request-management/fanavaran-hull-lookup-validation.ts @@ -1,6 +1,10 @@ import { asLookupRows } from "./fanavaran-hull-expertise-lookups"; export type HullLookupStage = "baseClaim" | "expertise" | "files"; + +/** Default AccidentCauseId (عدم رعايت حق تقدم) used when the case-selected value + * is not present in the live Fanavaran accident-causes lookup. */ +export const FANAVARAN_HULL_FALLBACK_ACCIDENT_CAUSE_ID = 6; type LookupField = { row: Record; key: string; @@ -105,11 +109,32 @@ export async function validateFanavaranHullLookupIds( (row.IsActive == null || Number(row.IsActive) !== 0), ) : undefined; - if (!matched) - warnings.push( - `${field.path}=${raw ?? "(missing)"} is not in the current ${field.lookup} API response.`, - ); - else field.row[field.key] = Number(matched.Id); + if (!matched) { + // For AccidentCauseId: auto-correct to the fallback instead of only warning, + // because سنهاب rejects unrecognised cause IDs with a hard error. + if (field.key === "AccidentCauseId" && stage === "baseClaim") { + const fallbackId = FANAVARAN_HULL_FALLBACK_ACCIDENT_CAUSE_ID; + const fallbackRow = sources + .get(field.lookup) + ?.find( + (row) => + row.Id != null && + Number(row.Id) === fallbackId && + row.IsActive !== false && + (row.IsActive == null || Number(row.IsActive) !== 0), + ); + field.row[field.key] = fallbackId; + warnings.push( + `${field.path}=${raw ?? "(missing)"} is not in the current ${field.lookup} API response; replaced with fallback AccidentCauseId=${fallbackId}${fallbackRow ? ` («${fallbackRow.Caption ?? fallbackRow.Name ?? fallbackId}»)` : ""}.`, + ); + } else { + warnings.push( + `${field.path}=${raw ?? "(missing)"} is not in the current ${field.lookup} API response.`, + ); + } + } else { + field.row[field.key] = Number(matched.Id); + } } return warnings; }