forked from Yara724/api
default sets to 6 when its 1 or its null
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import { asLookupRows } from "./fanavaran-hull-expertise-lookups";
|
import { asLookupRows } from "./fanavaran-hull-expertise-lookups";
|
||||||
|
|
||||||
export type HullLookupStage = "baseClaim" | "expertise" | "files";
|
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 = {
|
type LookupField = {
|
||||||
row: Record<string, unknown>;
|
row: Record<string, unknown>;
|
||||||
key: string;
|
key: string;
|
||||||
@@ -105,11 +109,32 @@ export async function validateFanavaranHullLookupIds(
|
|||||||
(row.IsActive == null || Number(row.IsActive) !== 0),
|
(row.IsActive == null || Number(row.IsActive) !== 0),
|
||||||
)
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
if (!matched)
|
if (!matched) {
|
||||||
warnings.push(
|
// For AccidentCauseId: auto-correct to the fallback instead of only warning,
|
||||||
`${field.path}=${raw ?? "(missing)"} is not in the current ${field.lookup} API response.`,
|
// because سنهاب rejects unrecognised cause IDs with a hard error.
|
||||||
);
|
if (field.key === "AccidentCauseId" && stage === "baseClaim") {
|
||||||
else field.row[field.key] = Number(matched.Id);
|
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;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user