forked from Yara724/api
culprit licence bug fixed , and handled some default values
This commit is contained in:
@@ -7,8 +7,54 @@ import {
|
||||
} from "./fanavaran-driver-inquiry";
|
||||
import type { FanavaranClaimProduct } from "./fanavaran-claim-product";
|
||||
|
||||
/** Fanavaran dummy licence issue date when the user did not supply one. */
|
||||
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1394/10/13";
|
||||
/**
|
||||
* Fanavaran dummy licence issue date when `person.driverLicenseDate` is missing.
|
||||
* Kept recent so hull `IsLicenseReplaced` stays null (see 10-year rule).
|
||||
*/
|
||||
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1404/08/20";
|
||||
|
||||
/** Years since issue after which hull/third-party "licence replaced?" becomes yes (1). */
|
||||
export const FANAVARAN_LICENCE_REPLACED_AFTER_YEARS = 10;
|
||||
|
||||
/**
|
||||
* True when `issueDate` is more than `years` before `referenceDate` (Jalali).
|
||||
* Used for Fanavaran IsLicenseReplaced / IsLicenseReplacement.
|
||||
*/
|
||||
export function isJalaliDateOlderThanYears(
|
||||
issueDate: unknown,
|
||||
referenceDate: unknown,
|
||||
years: number,
|
||||
): boolean {
|
||||
const issue = parseJalaliDateParts(issueDate);
|
||||
const reference = parseJalaliDateParts(referenceDate);
|
||||
if (!issue || !reference) return false;
|
||||
let age = reference.year - issue.year;
|
||||
if (
|
||||
reference.month < issue.month ||
|
||||
(reference.month === issue.month && reference.day < issue.day)
|
||||
) {
|
||||
age -= 1;
|
||||
}
|
||||
return age > years;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hull `IsLicenseReplaced` / ثالث `IsLicenseReplacement`:
|
||||
* - licence issue more than 10 years before accident → `1`
|
||||
* - otherwise → `null` (never send `0`)
|
||||
*/
|
||||
export function resolveFanavaranIsLicenseReplaced(
|
||||
licenceIssuDate: unknown,
|
||||
accidentDate: unknown,
|
||||
): 1 | null {
|
||||
return isJalaliDateOlderThanYears(
|
||||
licenceIssuDate,
|
||||
accidentDate,
|
||||
FANAVARAN_LICENCE_REPLACED_AFTER_YEARS,
|
||||
)
|
||||
? 1
|
||||
: null;
|
||||
}
|
||||
|
||||
export type FanavaranRoleIdentity = {
|
||||
nationalCode: string | null;
|
||||
|
||||
Reference in New Issue
Block a user