forked from Yara724/api
80 lines
3.2 KiB
TypeScript
80 lines
3.2 KiB
TypeScript
/**
|
|
* Converts the processed CAR_BODY policy returned by the ESG/Fanavaran lookup
|
|
* into the same mapped contract used by the existing car-body inquiry flow.
|
|
* The original response is deliberately kept separately as `raw` by the
|
|
* caller, so newly exposed provider fields are never discarded.
|
|
*/
|
|
export function mapEsgCarBodyPolicyToInquiry(
|
|
response: Record<string, any>,
|
|
): Record<string, unknown> {
|
|
const policy = response.policy ?? {};
|
|
const customer = response.customer ?? {};
|
|
const vehicle = response.vehicle ?? {};
|
|
const vehicleKind = vehicle.vehicleKind ?? {};
|
|
const usage = vehicle.used ?? {};
|
|
const plaque = vehicle.plaque ?? {};
|
|
|
|
const ownerName =
|
|
[customer.Name, customer.LastName]
|
|
.filter((value) => typeof value === "string" && value.trim())
|
|
.join(" ") || null;
|
|
|
|
return {
|
|
policyNumber: policy.CINumber ?? policy.PolicyNo ?? null,
|
|
policyId: response.policyId ?? policy.PolicyId ?? null,
|
|
contractId: policy.ContractId ?? null,
|
|
insuranceLine: response.insuranceLine ?? "CAR_BODY",
|
|
insuranceLineId: response.insuranceLineId ?? 4,
|
|
|
|
// Provider responses do not currently include an insurer company identity.
|
|
companyId: policy.CompanyId ?? null,
|
|
CompanyCode: policy.CompanyId ?? "8",
|
|
CompanyName: policy.CompanyName ?? "بیمه پارسیان",
|
|
|
|
// The lookup's customer is the policyholder/owner, not the insurer.
|
|
insurerName: null,
|
|
InsuranceFullName: null,
|
|
insurerNationalCode: null,
|
|
ownerNationalCode: customer.NationalCode ?? null,
|
|
ownerName,
|
|
customerName: customer.Name ?? null,
|
|
customerLastName: customer.LastName ?? null,
|
|
customerFatherName: customer.FatherName ?? null,
|
|
customerMobile: customer.Mobile ?? null,
|
|
customerAddress: customer.Address ?? null,
|
|
customerPostalCode: customer.PostalCode ?? null,
|
|
|
|
motorNumber: vehicle.MotorNo ?? null,
|
|
EngineNumberField: vehicle.MotorNo ?? null,
|
|
chassisNumber: vehicle.ChassisNo ?? null,
|
|
ChassisNumberField: vehicle.ChassisNo ?? null,
|
|
vin: vehicle.VIN ?? vehicle.ChassisNo ?? null,
|
|
VinNumberField: vehicle.VIN ?? vehicle.ChassisNo ?? null,
|
|
vehicleGroupTitle: vehicleKind.VehicleCategoryCaption ?? null,
|
|
vehicleSystemTitle: vehicleKind.VehicleSystemCaption ?? null,
|
|
vehicleKind: vehicleKind.Caption ?? null,
|
|
MapTypNam: vehicleKind.Caption ?? vehicleKind.VehicleSystemCaption ?? null,
|
|
builtYear: vehicle.BuiltYear ?? null,
|
|
cylinderCount: vehicleKind.CylinderCount ?? null,
|
|
passengerCount: vehicleKind.PassengerCount ?? null,
|
|
usage: usage.Caption ?? null,
|
|
|
|
IssueDate: policy.PolicyIssuDate ?? policy.IssuDate ?? null,
|
|
StartDate: policy.BeginDate ?? null,
|
|
EndDate: policy.EndDate ?? null,
|
|
vehicleValue: policy.VehicleValue ?? null,
|
|
totalPremium: policy.TotalPremium ?? null,
|
|
noLossYearsCount:
|
|
policy.YearsCountWithoutLoss ??
|
|
policy.AdditionalCovYearsCountWithoutLoss ??
|
|
null,
|
|
lossDocuments: [],
|
|
hasEndorsement: Number(policy.EndoNo ?? 0) > 0,
|
|
|
|
platePartOne: plaque.leftTwoDigits ?? vehicle.PlaqueLeftNo ?? null,
|
|
plateLetterTitle: plaque.serialLetter ?? null,
|
|
platePartThree: plaque.threeDigits ?? vehicle.PlaqueRightNo ?? null,
|
|
plateSerialNumber: plaque.rightTwoDigits ?? vehicle.PlaqueSerial ?? null,
|
|
};
|
|
}
|