100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
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';
|
|
|
|
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_addproduct_types {
|
|
evo_product_type
|
|
evo_addproduct_typeid
|
|
}
|
|
evo_category_tr
|
|
evo_vehicle_type_tax
|
|
evo_regionid
|
|
evo_townid
|
|
evo_legal_regionid
|
|
evo_legal_townid
|
|
evo_registration_regionid
|
|
}
|
|
}
|
|
`;
|
|
|
|
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 { getLegalRegion, getLegalTown, getRegion, getTown } = helper({
|
|
apolloClient,
|
|
});
|
|
|
|
const legalRegionId = await getLegalRegion({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
quote: quoteId,
|
|
});
|
|
|
|
const legalTownId = await getLegalTown({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
quote: quoteId,
|
|
regionId: legalRegionId,
|
|
});
|
|
|
|
const regionId = await getRegion({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
quote: quoteId,
|
|
});
|
|
|
|
const townId = await getTown({
|
|
lead: leadId,
|
|
opportunity: opportunityId,
|
|
quote: quoteId,
|
|
regionId,
|
|
});
|
|
|
|
const registration = quote?.evo_addproduct_types?.find(
|
|
(x) => x?.evo_product_type === 100_000_001
|
|
)?.evo_addproduct_typeid;
|
|
|
|
return {
|
|
values: {
|
|
legalClientRegion: legalRegionId,
|
|
legalClientTown: legalTownId,
|
|
objectCategoryTax: quote?.evo_category_tr,
|
|
objectRegionRegistration: quote?.evo_registration_regionid,
|
|
objectRegistration: recalcWithRevision
|
|
? quote?.evo_db_accept_registration
|
|
: quote?.evo_object_registration,
|
|
objectTypeTax: quote?.evo_vehicle_type_tax,
|
|
regionRegistration: regionId,
|
|
registration,
|
|
townRegistration: townId,
|
|
typePTS: quote?.evo_pts_type,
|
|
vehicleTaxInYear:
|
|
(recalcWithRevision ? quote?.evo_vehicle_tax_approved : quote?.evo_vehicle_tax_year) ??
|
|
defaultValues.vehicleTaxInYear,
|
|
},
|
|
};
|
|
}
|