103 lines
3.1 KiB
TypeScript
103 lines
3.1 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';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import { gql } from '@apollo/client';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const QUERY_GET_QUOTE_GIBDD_DATA = gql`
|
|
query GetQuoteGibddData($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_db_accept_registration
|
|
evo_object_registration
|
|
evo_pts_type
|
|
evo_vehicle_tax_year
|
|
evo_vehicle_tax_approved
|
|
evo_category_tr
|
|
evo_vehicle_type_tax
|
|
evo_regionid
|
|
evo_townid
|
|
evo_legal_regionid
|
|
evo_legal_townid
|
|
evo_registration_regionid
|
|
evo_req_telematic
|
|
evo_req_telematic_accept
|
|
}
|
|
}
|
|
`;
|
|
|
|
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
|
|
const { quote: quoteId, recalcWithRevision, lead: leadId, opportunity: opportunityId } = values;
|
|
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetQuoteGibddDataDocument,
|
|
variables: {
|
|
quoteId,
|
|
},
|
|
});
|
|
|
|
const { getData } = helper({
|
|
apolloClient,
|
|
});
|
|
|
|
const { account } = await getData({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
quote: null,
|
|
});
|
|
|
|
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,
|
|
},
|
|
};
|
|
}
|