61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
|
|
import defaultValues from '@/config/default-values';
|
|
import {
|
|
DEFAULT_FINGAP_ROW,
|
|
DEFAULT_KASKO_ROW,
|
|
DEFAULT_OSAGO_ROW,
|
|
} from '@/config/tables/insurance-table';
|
|
import { getKPData as getKPDataFingap } from '@/process/fingap/get-kp-data';
|
|
import { sum } from 'radash';
|
|
|
|
export async function getKPData({
|
|
values,
|
|
quote,
|
|
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
|
const kpDataFingap = await getKPDataFingap({ quote, values });
|
|
|
|
const risks = kpDataFingap.fingap?.risks;
|
|
|
|
let fingapInsCost = 0;
|
|
if (risks?.length) {
|
|
fingapInsCost = sum(
|
|
risks.filter((x) => kpDataFingap.fingap?.keys.includes(x.key)),
|
|
(risk) => risk.premium
|
|
);
|
|
}
|
|
|
|
return {
|
|
insurance: {
|
|
values: {
|
|
fingap: Object.assign(DEFAULT_FINGAP_ROW, {
|
|
insCost: fingapInsCost ?? DEFAULT_FINGAP_ROW.insCost,
|
|
insTerm: quote?.evo_fingap_period,
|
|
insuranceCompany: quote?.evo_fingap_accountid,
|
|
insured: quote?.evo_fingap_payer,
|
|
}),
|
|
kasko: Object.assign(DEFAULT_KASKO_ROW, {
|
|
insCost: quote?.evo_kasko_price ?? DEFAULT_KASKO_ROW.insCost,
|
|
insTerm: quote?.evo_insurance_period,
|
|
insuranceCompany: quote?.evo_kasko_accountid,
|
|
insured: quote?.evo_kasko_payer,
|
|
}),
|
|
osago: Object.assign(DEFAULT_OSAGO_ROW, {
|
|
insCost: quote?.evo_osago_price ?? DEFAULT_OSAGO_ROW.insCost,
|
|
insTerm: quote?.evo_insurance_period,
|
|
insuranceCompany: quote?.evo_osago_accountid,
|
|
insured: quote?.evo_osago_payer,
|
|
}),
|
|
},
|
|
},
|
|
values: {
|
|
GPSBrand: quote?.evo_gps_brandid,
|
|
GPSModel: quote?.evo_gps_modelid,
|
|
insAgeDrivers: quote?.evo_age_drivers ?? defaultValues.insAgeDrivers,
|
|
insDecentral: quote?.evo_insurance_decentral ?? defaultValues.insDecentral,
|
|
insExpDrivers: quote?.evo_exp_drivers ?? defaultValues.insExpDrivers,
|
|
insFranchise: quote?.evo_franchise ?? defaultValues.insFranchise,
|
|
insUnlimitDrivers: quote?.evo_unlimit_drivers ?? defaultValues.insUnlimitDrivers,
|
|
},
|
|
};
|
|
}
|