forked from Yara724/api
Map Fanavaran people and licences by party role; allow unlisted base-info lookups.
Resolve driver, owner, and policyholder from participants when they differ, prefer real licence / driverLicenseDate over dummies, and fall back unknown /lookups/fanavaran/{name} to car/base-info/{name} (including vehicle-groups).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,6 +34,21 @@ export function asPartyInquiryRows(value: unknown): FanavaranPartyInquiryRow[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
function selectFanavaranIdByRoles(
|
||||
rows: unknown,
|
||||
preferredRoles: number[],
|
||||
): number | null {
|
||||
const parties = asPartyInquiryRows(rows);
|
||||
if (parties.length === 0) return null;
|
||||
|
||||
for (const roleId of preferredRoles) {
|
||||
const match = parties.find((row) => asPositiveId(row.RoleId) === roleId);
|
||||
if (match) return asPositiveId(match.Id);
|
||||
}
|
||||
|
||||
return asPositiveId(parties[0].Id);
|
||||
}
|
||||
|
||||
/**
|
||||
* DriverId for GEN.12 زیاندیده. Prefer insurer (161) or driver (166)
|
||||
* based on driverIsInsurer, then any returned party id.
|
||||
@@ -42,19 +57,27 @@ export function selectFanavaranDriverId(
|
||||
rows: unknown,
|
||||
driverIsInsurer: boolean | undefined,
|
||||
): number | null {
|
||||
const parties = asPartyInquiryRows(rows);
|
||||
if (parties.length === 0) return null;
|
||||
|
||||
const preferredRoles = driverIsInsurer
|
||||
? [FANAVARAN_INSURER_ROLE_ID, FANAVARAN_DRIVER_ROLE_ID, FANAVARAN_PLAQUE_OWNER_ROLE_ID]
|
||||
: [FANAVARAN_DRIVER_ROLE_ID, FANAVARAN_INSURER_ROLE_ID, FANAVARAN_PLAQUE_OWNER_ROLE_ID];
|
||||
? [
|
||||
FANAVARAN_INSURER_ROLE_ID,
|
||||
FANAVARAN_DRIVER_ROLE_ID,
|
||||
FANAVARAN_PLAQUE_OWNER_ROLE_ID,
|
||||
]
|
||||
: [
|
||||
FANAVARAN_DRIVER_ROLE_ID,
|
||||
FANAVARAN_INSURER_ROLE_ID,
|
||||
FANAVARAN_PLAQUE_OWNER_ROLE_ID,
|
||||
];
|
||||
return selectFanavaranIdByRoles(rows, preferredRoles);
|
||||
}
|
||||
|
||||
for (const roleId of preferredRoles) {
|
||||
const match = parties.find((row) => asPositiveId(row.RoleId) === roleId);
|
||||
if (match) return asPositiveId(match.Id);
|
||||
}
|
||||
|
||||
return asPositiveId(parties[0].Id);
|
||||
/** OwnerId: prefer plaque-owner role (163), then insurer / driver. */
|
||||
export function selectFanavaranOwnerId(rows: unknown): number | null {
|
||||
return selectFanavaranIdByRoles(rows, [
|
||||
FANAVARAN_PLAQUE_OWNER_ROLE_ID,
|
||||
FANAVARAN_INSURER_ROLE_ID,
|
||||
FANAVARAN_DRIVER_ROLE_ID,
|
||||
]);
|
||||
}
|
||||
|
||||
export function normalizeNationalCode(value: unknown): string | null {
|
||||
|
||||
Reference in New Issue
Block a user