72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
/* eslint-disable sonarjs/cognitive-complexity */
|
|
import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
|
|
import helper from './lib/helper';
|
|
import initializeApollo from '@/apollo/client';
|
|
import defaultValues from '@/config/default-values';
|
|
|
|
export async function getKPData({
|
|
values,
|
|
quote,
|
|
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
|
const { recalcWithRevision, lead: leadId, opportunity: opportunityId } = values;
|
|
|
|
const apolloClient = initializeApollo();
|
|
|
|
const { getData } = helper({
|
|
apolloClient,
|
|
});
|
|
|
|
const { account } = await getData({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
});
|
|
|
|
const objectRegistration = recalcWithRevision
|
|
? quote?.evo_db_accept_registration
|
|
: quote?.evo_object_registration;
|
|
|
|
const typePTS = objectRegistration === 100_000_000 ? defaultValues.typePTS : quote?.evo_pts_type;
|
|
|
|
// region
|
|
let legalClientRegion = quote?.evo_legal_regionid ?? defaultValues.legalClientRegion;
|
|
if (account?.evo_legal_regionid) {
|
|
legalClientRegion = account.evo_legal_regionid;
|
|
}
|
|
|
|
let regionRegistration = quote?.evo_regionid ?? defaultValues.regionRegistration;
|
|
if (objectRegistration === 100_000_000 && account?.evo_legal_regionid) {
|
|
regionRegistration = account.evo_legal_regionid;
|
|
}
|
|
|
|
// town
|
|
let legalClientTown = quote?.evo_legal_townid ?? defaultValues.legalClientTown;
|
|
if (account?.evo_legal_townid) {
|
|
legalClientTown = account?.evo_legal_townid;
|
|
}
|
|
|
|
let townRegistration = quote?.evo_townid ?? defaultValues.townRegistration;
|
|
if (objectRegistration === 100_000_000 && account?.evo_legal_townid) {
|
|
townRegistration = account?.evo_legal_townid;
|
|
}
|
|
|
|
return {
|
|
values: {
|
|
legalClientRegion,
|
|
legalClientTown,
|
|
objectCategoryTax: quote?.evo_category_tr,
|
|
objectRegionRegistration: quote?.evo_registration_regionid,
|
|
objectRegistration,
|
|
objectTypeTax: quote?.evo_vehicle_type_tax,
|
|
regionRegistration,
|
|
requirementTelematic:
|
|
(recalcWithRevision ? quote?.evo_req_telematic_accept : quote?.evo_req_telematic) ??
|
|
defaultValues.requirementTelematic,
|
|
townRegistration,
|
|
typePTS,
|
|
vehicleTaxInYear:
|
|
(recalcWithRevision ? quote?.evo_vehicle_tax_approved : quote?.evo_vehicle_tax_year) ??
|
|
defaultValues.vehicleTaxInYear,
|
|
},
|
|
};
|
|
}
|