56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
import { gql } from '@apollo/client';
|
|
import initializeApollo from 'apollo/client';
|
|
import type * as CRMTypes from 'graphql/crm.types';
|
|
import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types';
|
|
|
|
const QUERY_GET_LEASING_OBJECT_DATA_FROM_QUOTE = gql`
|
|
query GetLeasingObjectDataFromQuote($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_brandid
|
|
evo_modelid
|
|
evo_equipmentid
|
|
evo_leasingobject_typeid
|
|
}
|
|
}
|
|
`;
|
|
|
|
export type Quote = NonNullable<CRMTypes.GetLeasingObjectDataFromQuoteQuery['quote']>;
|
|
|
|
type QuoteLeasingObjectProcessData = {
|
|
values: Partial<GetQuoteDataOutput['values']>;
|
|
};
|
|
|
|
export default async function getLeasingObjectDataFromKP({
|
|
values: { quote: quoteId },
|
|
}: GetQuoteDataInput): Promise<QuoteLeasingObjectProcessData> {
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query<
|
|
CRMTypes.GetLeasingObjectDataFromQuoteQuery,
|
|
CRMTypes.GetLeasingObjectDataFromQuoteQueryVariables
|
|
>({
|
|
query: QUERY_GET_LEASING_OBJECT_DATA_FROM_QUOTE,
|
|
variables: {
|
|
quoteId,
|
|
},
|
|
});
|
|
|
|
if (!quote) {
|
|
throw new Error('Quote is empty');
|
|
}
|
|
|
|
const { evo_brandid, evo_modelid, evo_equipmentid, evo_leasingobject_typeid } = quote;
|
|
|
|
return {
|
|
values: {
|
|
brand: evo_brandid,
|
|
model: evo_modelid,
|
|
configuration: evo_equipmentid,
|
|
leaseObjectType: evo_leasingobject_typeid,
|
|
},
|
|
};
|
|
}
|