load-kp: get leaseObjectType, brand, model from quote

This commit is contained in:
vchikalkin 2023-01-25 14:33:02 +03:00
parent ce4a8ad2c1
commit 34c4c130be
4 changed files with 73 additions and 1 deletions

View File

@ -231,6 +231,13 @@ export type GetQuoteUrlQueryVariables = Exact<{
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
export type GetLeasingObjectDataFromQuoteQueryVariables = Exact<{
quoteId: Scalars['Uuid'];
}>;
export type GetLeasingObjectDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_brandid: string | null, evo_modelid: string | null, evo_leasingobject_typeid: string | null } | null };
export type GetModels_ProcessLeasingObjectQueryVariables = Exact<{
brandid: Scalars['Uuid'];
}>;

View File

@ -0,0 +1,53 @@
/* 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_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_leasingobject_typeid } = quote;
return {
values: {
brand: evo_brandid,
model: evo_modelid,
leaseObjectType: evo_leasingobject_typeid,
},
};
}

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types';
import { autorun } from 'mobx';
import { autorun, reaction } from 'mobx';
import type { ReactionsContext } from 'process/types';
import { intersects } from 'radash';
import { normalizeOptions } from 'tools';
@ -341,4 +341,13 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
delay: 10,
}
);
reaction(
() => $calculation.element('selectLeaseObjectType').getValue(),
(leaseObjctType) => {
if (!leaseObjctType) {
$calculation.element('selectBrand').resetValue();
}
}
);
}

View File

@ -1,6 +1,7 @@
import defaultValues from 'config/default-values';
import { defaultValues as defaultInsuranceValues } from 'config/tables/insurance-table';
import getFingapDataFromKP from 'process/fingap/get-kp-data';
import getLeasingObjectDataFromKP from 'process/leasing-object/get-kp-data';
import { GetQuoteDataInputSchema, GetQuoteDataOutputSchema } from 'process/load-kp/types';
import getPaymentsDataFromKP from 'process/payments/get-kp-data';
import getSupplierAgentsDataFromKP from 'process/supplier-agent/get-kp-values';
@ -16,6 +17,7 @@ const quoteRouter = t.router({
.query(async ({ input }) => {
const { values: supplierAgentsValues } = await getSupplierAgentsDataFromKP(input);
const { values: paymentsValues, payments } = await getPaymentsDataFromKP(input);
const { values: leasingObjectValues } = await getLeasingObjectDataFromKP(input);
const { fingap, insurance: fingapInsurance } = await getFingapDataFromKP(input);
return {
@ -23,6 +25,7 @@ const quoteRouter = t.router({
...defaultValues,
...supplierAgentsValues,
...paymentsValues,
...leasingObjectValues,
},
payments,
insurance: {