default sets to 6 when its 1 or its null

This commit is contained in:
2026-11-12 17:51:45 +03:30
parent 457fd0b174
commit 9178058173
@@ -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<string, unknown>;
key: string;
@@ -105,11 +109,32 @@ export async function validateFanavaranHullLookupIds(
(row.IsActive == null || Number(row.IsActive) !== 0),
)
: undefined;
if (!matched)
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);
}
} else {
field.row[field.key] = Number(matched.Id);
}
}
return warnings;
}