70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types';
|
|
import initializeApollo from '@/apollo/client';
|
|
import { defaultValues } from '@/config/tables/insurance-table';
|
|
import type * as CRMTypes from '@/graphql/crm.types';
|
|
import { gql } from '@apollo/client';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
const DEFAULT_FINGAP_ROW = defaultValues.find((x) => x.key === 'fingap')!;
|
|
|
|
const QUERY_GET_FINGAP_DATA_FROM_QUOTE = gql`
|
|
query GetFingapDataFromQuote($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_fingap_accountid
|
|
evo_fingap_payer
|
|
evo_fingap_period
|
|
evo_product_risks {
|
|
evo_addproduct_typeid
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
type QuoteFingapProcessData = {
|
|
fingap: GetQuoteDataOutput['fingap'];
|
|
insurance: {
|
|
values: Pick<GetQuoteDataOutput['insurance']['values'], 'fingap'>;
|
|
};
|
|
};
|
|
|
|
export default async function getFingapDataFromKP({
|
|
values: { quote: quoteId },
|
|
}: GetQuoteDataInput): Promise<QuoteFingapProcessData> {
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query<
|
|
CRMTypes.GetFingapDataFromQuoteQuery,
|
|
CRMTypes.GetFingapDataFromQuoteQueryVariables
|
|
>({
|
|
query: QUERY_GET_FINGAP_DATA_FROM_QUOTE,
|
|
variables: {
|
|
quoteId,
|
|
},
|
|
});
|
|
|
|
const keys: string[] = [];
|
|
quote?.evo_product_risks?.forEach((x) => {
|
|
if (x?.evo_addproduct_typeid) {
|
|
keys.push(x.evo_addproduct_typeid);
|
|
}
|
|
});
|
|
|
|
return {
|
|
fingap: {
|
|
keys,
|
|
},
|
|
insurance: {
|
|
values: {
|
|
fingap: {
|
|
...DEFAULT_FINGAP_ROW,
|
|
insTerm: quote?.evo_fingap_period || null,
|
|
insuranceCompany: quote?.evo_fingap_accountid || null,
|
|
insured: quote?.evo_fingap_payer || null,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|