From 57d7e5907cfd220136e046ab61a481d11c225891 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 23 Feb 2023 21:58:25 +0300 Subject: [PATCH] process/gibdd: add load-kp-data --- apps/web/graphql/crm.query.graphql | 6 + apps/web/graphql/crm.types.ts | 24 +++ apps/web/process/gibdd/get-kp-data.ts | 120 +++++++++++ apps/web/process/gibdd/index.ts | 1 + apps/web/process/gibdd/lib/helper.ts | 288 ++++++++++++++++++++++++++ apps/web/process/gibdd/reactions.ts | 173 ++++------------ apps/web/process/load-kp/reactions.ts | 4 +- apps/web/process/load-kp/types.ts | 4 +- apps/web/trpc/routers/quote.ts | 3 + 9 files changed, 490 insertions(+), 133 deletions(-) create mode 100644 apps/web/process/gibdd/get-kp-data.ts create mode 100644 apps/web/process/gibdd/lib/helper.ts diff --git a/apps/web/graphql/crm.query.graphql b/apps/web/graphql/crm.query.graphql index 0e60f8f..a03234a 100644 --- a/apps/web/graphql/crm.query.graphql +++ b/apps/web/graphql/crm.query.graphql @@ -435,3 +435,9 @@ query GetRegistrationTypes($currentDate: DateTime) { evo_towtruck } } + +query GetAddProductType($addproductTypeId: Uuid!) { + evo_addproduct_type(evo_addproduct_typeid: $addproductTypeId) { + evo_description + } +} diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 3c1d17c..7a848ae 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -393,6 +393,13 @@ export type GetRegistrationTypesQueryVariables = Exact<{ export type GetRegistrationTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_whom_register: number | null, evo_gibdd_region: boolean | null, evo_pts_type: Array | null, evo_accountid: string | null, evo_towtruck: boolean | null, label: string | null, value: string | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null } | null> | null }; +export type GetAddProductTypeQueryVariables = Exact<{ + addproductTypeId: Scalars['Uuid']; +}>; + + +export type GetAddProductTypeQuery = { __typename?: 'Query', evo_addproduct_type: { __typename?: 'evo_addproduct_type', evo_description: string | null } | null }; + export type GetBonusDataFromQuoteQueryVariables = Exact<{ quoteId: Scalars['Uuid']; }>; @@ -421,6 +428,20 @@ export type GetFinGapAddProductTypesQueryVariables = Exact<{ export type GetFinGapAddProductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null, evo_name: string | null, evo_type_calc_cerebellum: number | null, evo_cost_service_provider_withoutnds: number | null, evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_addproduct_typeid: string | null } | null> | null } | null> | null }; +export type GetGibddDataFromQuoteQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetGibddDataFromQuoteQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_db_accept_registration: number | null, evo_object_registration: number | null, evo_pts_type: number | null, evo_vehicle_tax_year: number | null, evo_vehicle_tax_approved: number | null, evo_category_tr: number | null, evo_vehicle_type_tax: number | null, evo_regionid: string | null, evo_townid: string | null, evo_legal_regionid: string | null, evo_legal_townid: string | null, evo_registration_regionid: string | null, evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_product_type: number | null, evo_addproduct_typeid: string | null } | null> | null } | null }; + +export type GetQuoteRegionTownQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetQuoteRegionTownQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_regionid: string | null, evo_townid: string | null, evo_legal_regionid: string | null, evo_legal_townid: string | null } | null }; + export type GetInsuranceDataQueryVariables = Exact<{ evo_account_type: InputMaybe | Scalars['Int']>; }>; @@ -533,10 +554,13 @@ export const GetCoefficientsDocument = {"kind":"Document","definitions":[{"kind" export const GetSystemUserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSystemUser"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemuser"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_job_titleid"}}]}}]}}]} as unknown as DocumentNode; export const GetAddproductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAddproductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}}]}}]}}]} as unknown as DocumentNode; export const GetRegistrationTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegistrationTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000001"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_whom_register"}},{"kind":"Field","name":{"kind":"Name","value":"evo_gibdd_region"}},{"kind":"Field","name":{"kind":"Name","value":"evo_pts_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_towtruck"}}]}}]}}]} as unknown as DocumentNode; +export const GetAddProductTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAddProductType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"addproductTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_addproduct_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"addproductTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_description"}}]}}]}}]} as unknown as DocumentNode; export const GetBonusDataFromQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetBonusDataFromQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sale_bonus"}}]}}]}}]} as unknown as DocumentNode; export const GetConfiguratorDataFromQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetConfiguratorDataFromQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}}]}}]} as unknown as DocumentNode; export const GetFingapDataFromQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetFingapDataFromQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_fingap_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fingap_payer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fingap_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_product_risks"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetFinGapAddProductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetFinGAPAddProductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000006"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_type_calc_cerebellum"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_service_provider_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; +export const GetGibddDataFromQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetGibddDataFromQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_db_accept_registration"}},{"kind":"Field","name":{"kind":"Name","value":"evo_object_registration"}},{"kind":"Field","name":{"kind":"Name","value":"evo_pts_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_tax_year"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_tax_approved"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_category_tr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type_tax"}},{"kind":"Field","name":{"kind":"Name","value":"evo_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_townid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_townid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_registration_regionid"}}]}}]}}]} as unknown as DocumentNode; +export const GetQuoteRegionTownDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteRegionTown"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_townid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_regionid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_legal_townid"}}]}}]}}]} as unknown as DocumentNode; export const GetInsuranceDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsuranceData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"osago"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000001"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"kasko"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000000"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"fingap"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000002"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}}]}}]} as unknown as DocumentNode; export const GetLeadUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeadUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"entity"},"name":{"kind":"Name","value":"lead"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode; export const GetOpportunityUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunityUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"entity"},"name":{"kind":"Name","value":"opportunity"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"opportunityid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/gibdd/get-kp-data.ts b/apps/web/process/gibdd/get-kp-data.ts new file mode 100644 index 0000000..10b5ec5 --- /dev/null +++ b/apps/web/process/gibdd/get-kp-data.ts @@ -0,0 +1,120 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types'; +import helper from './lib/helper'; +import initializeApollo from '@/apollo/client'; +import type * as CRMTypes from '@/graphql/crm.types'; +import { gql } from '@apollo/client'; + +const QUERY_GET_GIBDD_DATA_FROM_QUOTE = gql` + query GetGibddDataFromQuote($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 type Quote = NonNullable; + +type QuoteLeasingObjectProcessData = { + values: Partial; +}; + +export async function getKPData({ + values: { quote: quoteId, recalcWithRevision, lead: leadId, opportunity: opportunityId }, +}: GetQuoteDataInput): Promise { + const apolloClient = initializeApollo(); + + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetGibddDataFromQuoteQuery, + CRMTypes.GetGibddDataFromQuoteQueryVariables + >({ + query: QUERY_GET_GIBDD_DATA_FROM_QUOTE, + variables: { + quoteId, + }, + }); + + if (!quote) { + throw new Error('Quote is empty'); + } + + 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 { + evo_db_accept_registration, + evo_object_registration, + evo_pts_type, + evo_vehicle_tax_approved, + evo_vehicle_tax_year, + evo_registration_regionid, + evo_addproduct_types, + evo_category_tr, + evo_vehicle_type_tax, + } = quote; + + const registration = evo_addproduct_types?.find( + (x) => x?.evo_product_type === 100_000_001 + )?.evo_addproduct_typeid; + + return { + values: { + legalClientRegion: legalRegionId, + legalClientTown: legalTownId, + objectCategoryTax: evo_category_tr, + objectRegionRegistration: evo_registration_regionid, + objectRegistration: recalcWithRevision ? evo_db_accept_registration : evo_object_registration, + objectTypeTax: evo_vehicle_type_tax ?? undefined, + regionRegistration: regionId, + registration, + townRegistration: townId, + typePTS: evo_pts_type, + vehicleTaxInYear: + (recalcWithRevision ? evo_vehicle_tax_approved : evo_vehicle_tax_year) ?? undefined, + }, + }; +} diff --git a/apps/web/process/gibdd/index.ts b/apps/web/process/gibdd/index.ts index 88c740a..e05ea2d 100644 --- a/apps/web/process/gibdd/index.ts +++ b/apps/web/process/gibdd/index.ts @@ -1 +1,2 @@ +export * from './get-kp-data'; export * as reactions from './reactions'; diff --git a/apps/web/process/gibdd/lib/helper.ts b/apps/web/process/gibdd/lib/helper.ts new file mode 100644 index 0000000..5a5eae9 --- /dev/null +++ b/apps/web/process/gibdd/lib/helper.ts @@ -0,0 +1,288 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import * as CRMTypes from '@/graphql/crm.types'; +import type { ProcessContext } from '@/process/types'; +import type { CalculationValues } from '@/stores/calculation/values/types'; +import { gql } from '@apollo/client'; + +const QUERY_GET_QUOTE_REGION_TOWN = gql` + query GetQuoteRegionTown($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_regionid + evo_townid + evo_legal_regionid + evo_legal_townid + } + } +`; + +export default function helper({ apolloClient }: Pick) { + return { + async getLegalRegion({ + lead: leadid, + opportunity: opportunityid, + quote: quoteId, + }: Pick) { + let regionId: string | null | undefined; + + const { + data: { evo_regions }, + } = await apolloClient.query({ + query: CRMTypes.GetRegionsDocument, + }); + + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: CRMTypes.GetLeadDocument, + variables: { leadid }, + }); + if (lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id) { + const region = evo_regions?.find( + (x) => + x?.evo_fias_id === lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id + ); + regionId = region?.value; + } + } + + if (opportunityid) { + const { + data: { opportunity }, + } = await apolloClient.query({ + query: CRMTypes.GetOpportunityDocument, + variables: { opportunityid }, + }); + + if (!regionId && opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id) { + const region = evo_regions?.find( + (x) => + x?.evo_fias_id === + opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id + ); + regionId = region?.value; + } + } + + if (!regionId && quoteId) { + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetQuoteRegionTownQuery, + CRMTypes.GetQuoteRegionTownQueryVariables + >({ + query: QUERY_GET_QUOTE_REGION_TOWN, + variables: { quoteId }, + }); + regionId = quote?.evo_legal_regionid; + } + + return regionId; + }, + + async getLegalTown({ + lead: leadid, + opportunity: opportunityid, + quote: quoteId, + regionId, + }: Pick & { + regionId: string | null | undefined; + }) { + if (!regionId) { + return null; + } + + let townId: string | null | undefined; + + const { + data: { evo_towns }, + } = await apolloClient.query({ + query: CRMTypes.GetTownsDocument, + variables: { regionId }, + }); + + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: CRMTypes.GetLeadDocument, + variables: { leadid }, + }); + if (lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id) { + const town = evo_towns?.find( + (x) => x?.evo_fias_id === lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id + ); + townId = town?.value; + } + } + + if (opportunityid) { + const { + data: { opportunity }, + } = await apolloClient.query({ + query: CRMTypes.GetOpportunityDocument, + variables: { opportunityid }, + }); + + if (!townId && opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id) { + const town = evo_towns?.find( + (x) => + x?.evo_fias_id === + opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id + ); + townId = town?.value; + } + } + + if (!townId && quoteId) { + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetQuoteRegionTownQuery, + CRMTypes.GetQuoteRegionTownQueryVariables + >({ + query: QUERY_GET_QUOTE_REGION_TOWN, + variables: { quoteId }, + }); + townId = quote?.evo_legal_townid; + } + + return townId; + }, + + async getRegion({ + lead: leadid, + opportunity: opportunityid, + quote: quoteId, + }: Pick) { + let regionId: string | null | undefined; + + const { + data: { evo_regions }, + } = await apolloClient.query({ + query: CRMTypes.GetRegionsDocument, + }); + + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: CRMTypes.GetLeadDocument, + variables: { leadid }, + }); + if (lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id) { + const region = evo_regions?.find( + (x) => + x?.evo_fias_id === lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id + ); + regionId = region?.value; + } + } + + if (opportunityid) { + const { + data: { opportunity }, + } = await apolloClient.query({ + query: CRMTypes.GetOpportunityDocument, + variables: { opportunityid }, + }); + + if (!regionId && opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id) { + const region = evo_regions?.find( + (x) => + x?.evo_fias_id === + opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id + ); + regionId = region?.value; + } + } + + if (!regionId && quoteId) { + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetQuoteRegionTownQuery, + CRMTypes.GetQuoteRegionTownQueryVariables + >({ + query: QUERY_GET_QUOTE_REGION_TOWN, + variables: { quoteId }, + }); + regionId = quote?.evo_regionid; + } + + return regionId; + }, + + async getTown({ + lead: leadid, + opportunity: opportunityid, + quote: quoteId, + regionId, + }: Pick & { + regionId: string | null | undefined; + }) { + if (!regionId) { + return null; + } + + let townId: string | null | undefined; + + const { + data: { evo_towns }, + } = await apolloClient.query({ + query: CRMTypes.GetTownsDocument, + variables: { regionId }, + }); + + if (leadid) { + const { + data: { lead }, + } = await apolloClient.query({ + query: CRMTypes.GetLeadDocument, + variables: { leadid }, + }); + if (lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id) { + const town = evo_towns?.find( + (x) => x?.evo_fias_id === lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id + ); + townId = town?.value; + } + } + + if (opportunityid) { + const { + data: { opportunity }, + } = await apolloClient.query({ + query: CRMTypes.GetOpportunityDocument, + variables: { opportunityid }, + }); + + if (!townId && opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id) { + const town = evo_towns?.find( + (x) => + x?.evo_fias_id === + opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id + ); + townId = town?.value; + } + } + + if (quoteId) { + const { + data: { quote }, + } = await apolloClient.query< + CRMTypes.GetQuoteRegionTownQuery, + CRMTypes.GetQuoteRegionTownQueryVariables + >({ + query: QUERY_GET_QUOTE_REGION_TOWN, + variables: { quoteId }, + }); + if (!townId && quote?.evo_townid) { + townId = quote?.evo_townid; + } + } + + return townId; + }, + }; +} diff --git a/apps/web/process/gibdd/reactions.ts b/apps/web/process/gibdd/reactions.ts index f12540f..f314d72 100644 --- a/apps/web/process/gibdd/reactions.ts +++ b/apps/web/process/gibdd/reactions.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import type { ProcessContext } from '../types'; +import helper from './lib/helper'; import { getTransTax } from '@/api/1c/query'; import { selectObjectCategoryTax } from '@/config/default-options'; import { STALE_TIME } from '@/constants/request'; @@ -388,58 +389,39 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { } ); + const { getLegalRegion, getLegalTown, getRegion, getTown } = helper({ apolloClient }); + reaction( () => $calculation.$values.getValues(['lead', 'opportunity']), - async ({ lead: leadid, opportunity: opportunityid }) => { - if (!leadid && !opportunityid) { + async ({ lead, opportunity }) => { + if (!lead && !opportunity) { $calculation.element('selectLegalClientRegion').resetValue().unblock(); $calculation.element('selectRegionRegistration').resetValue().unblock(); return; } - let evo_region_fias_id: string | undefined; + const quote = $calculation.element('selectQuote').getValue(); - if (leadid) { - const { - data: { lead }, - } = await apolloClient.query({ - query: CRMTypes.GetLeadDocument, - variables: { leadid }, - }); - if (lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id) - evo_region_fias_id = lead?.accountidData?.evo_address_legalidData?.evo_region_fias_id; - } - - if (opportunityid) { - const { - data: { opportunity }, - } = await apolloClient.query({ - query: CRMTypes.GetOpportunityDocument, - variables: { opportunityid }, - }); - - if ( - !evo_region_fias_id && - opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id - ) - evo_region_fias_id = - opportunity?.accountidData?.evo_address_legalidData?.evo_region_fias_id; - } - - const { - data: { evo_regions }, - } = await apolloClient.query({ - query: CRMTypes.GetRegionsDocument, + const legalRegionId = await getLegalRegion({ + lead, + opportunity, + quote, }); - - const region = evo_regions?.find((x) => x?.evo_fias_id === evo_region_fias_id); - - if (region) { - $calculation.element('selectLegalClientRegion').setValue(region.value).block(); - $calculation.element('selectRegionRegistration').setValue(region.value).block(); + if (legalRegionId) { + $calculation.element('selectLegalClientRegion').setValue(legalRegionId).block(); } else { $calculation.element('selectLegalClientRegion').resetValue().unblock(); + } + + const regionId = await getRegion({ + lead, + opportunity, + quote, + }); + if (regionId) { + $calculation.element('selectRegionRegistration').setValue(regionId).block(); + } else { $calculation.element('selectRegionRegistration').resetValue().unblock(); } } @@ -454,52 +436,18 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { return; } - const leadid = $calculation.element('selectLead').getValue(); - const opportunityid = $calculation.element('selectOpportunity').getValue(); + const lead = $calculation.element('selectLead').getValue(); + const opportunity = $calculation.element('selectOpportunity').getValue(); + const quote = $calculation.element('selectQuote').getValue(); - let evo_city_fias_id: string | undefined; - - if (leadid) { - const { - data: { lead }, - } = await apolloClient.query({ - query: CRMTypes.GetLeadDocument, - variables: { leadid }, - }); - - if (lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id) - evo_city_fias_id = lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id; - } - - if (opportunityid) { - const { - data: { opportunity }, - } = await apolloClient.query({ - query: CRMTypes.GetOpportunityDocument, - variables: { opportunityid }, - }); - - if ( - !evo_city_fias_id && - opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id - ) - evo_city_fias_id = opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id; - } - - if (evo_city_fias_id) { - const { - data: { evo_towns }, - } = await apolloClient.query({ - query: CRMTypes.GetTownsDocument, - variables: { regionId }, - }); - - const town = evo_towns?.find((x) => x?.evo_fias_id === evo_city_fias_id); - if (town) { - $calculation.element('selectLegalClientTown').setValue(town.value).block(); - } else { - $calculation.element('selectLegalClientTown').resetValue().unblock(); - } + const townId = await getLegalTown({ + lead, + opportunity, + quote, + regionId, + }); + if (townId) { + $calculation.element('selectLegalClientTown').setValue(townId).block(); } else { $calculation.element('selectLegalClientTown').resetValue().unblock(); } @@ -515,52 +463,19 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) { return; } - const leadid = $calculation.element('selectLead').getValue(); - const opportunityid = $calculation.element('selectOpportunity').getValue(); + const lead = $calculation.element('selectLead').getValue(); + const opportunity = $calculation.element('selectOpportunity').getValue(); + const quote = $calculation.element('selectQuote').getValue(); - let evo_city_fias_id: string | undefined; + const townId = await getTown({ + lead, + opportunity, + quote, + regionId, + }); - if (leadid) { - const { - data: { lead }, - } = await apolloClient.query({ - query: CRMTypes.GetLeadDocument, - variables: { leadid }, - }); - - if (lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id) - evo_city_fias_id = lead?.accountidData?.evo_address_legalidData?.evo_city_fias_id; - } - - if (opportunityid) { - const { - data: { opportunity }, - } = await apolloClient.query({ - query: CRMTypes.GetOpportunityDocument, - variables: { opportunityid }, - }); - - if ( - !evo_city_fias_id && - opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id - ) - evo_city_fias_id = opportunity?.accountidData?.evo_address_legalidData?.evo_city_fias_id; - } - - if (evo_city_fias_id && objectRegistration === 100_000_000) { - const { - data: { evo_towns }, - } = await apolloClient.query({ - query: CRMTypes.GetTownsDocument, - variables: { regionId }, - }); - - const town = evo_towns?.find((x) => x?.evo_fias_id === evo_city_fias_id); - if (town) { - $calculation.element('selectTownRegistration').setValue(town.value).block(); - } else { - $calculation.element('selectTownRegistration').resetValue().unblock(); - } + if (townId && objectRegistration === 100_000_000) { + $calculation.element('selectTownRegistration').setValue(townId).block(); } else { $calculation.element('selectTownRegistration').resetValue().unblock(); } diff --git a/apps/web/process/load-kp/reactions.ts b/apps/web/process/load-kp/reactions.ts index c8f7811..1a1edf4 100644 --- a/apps/web/process/load-kp/reactions.ts +++ b/apps/web/process/load-kp/reactions.ts @@ -22,13 +22,11 @@ export function common({ store, trpcClient }: ProcessContext) { key, }); - const recalcWithRevision = $calculation.element('cbxRecalcWithRevision').getValue(); - trpcClient.quote.getData .query({ values: { quote: quoteId, - recalcWithRevision, + ...$calculation.$values.getValues(['recalcWithRevision', 'lead', 'opportunity']), }, }) .then(({ values, payments, insurance, fingap }) => { diff --git a/apps/web/process/load-kp/types.ts b/apps/web/process/load-kp/types.ts index 747d75f..d669a6c 100644 --- a/apps/web/process/load-kp/types.ts +++ b/apps/web/process/load-kp/types.ts @@ -5,8 +5,10 @@ import PaymentsSchema from '@/config/schema/payments'; import ValuesSchema from '@/config/schema/values'; import { z } from 'zod'; -const { quote, recalcWithRevision } = ValuesSchema.shape; +const { quote, recalcWithRevision, lead, opportunity } = ValuesSchema.shape; const InputValuesSchema = z.object({ + lead, + opportunity, quote: quote.unwrap(), recalcWithRevision, }); diff --git a/apps/web/trpc/routers/quote.ts b/apps/web/trpc/routers/quote.ts index 46f5ff1..d7c6781 100644 --- a/apps/web/trpc/routers/quote.ts +++ b/apps/web/trpc/routers/quote.ts @@ -5,6 +5,7 @@ import { defaultValues as defaultInsuranceValues } from '@/config/tables/insuran import * as bonuses from '@/process/bonuses'; import * as configurator from '@/process/configurator'; import * as fingapProcess from '@/process/fingap'; +import * as gibdd from '@/process/gibdd'; import * as leasingObject from '@/process/leasing-object'; import * as loadKP from '@/process/load-kp'; import * as paymentsProcess from '@/process/payments'; @@ -29,6 +30,7 @@ const quoteRouter = t.router({ const { values: bonusesValues } = await bonuses.getKPData(input); const { values: leasingObjectValues } = await leasingObject.getKPData(input); const { fingap, insurance: fingapInsurance } = await fingapProcess.getKPData(input); + const { values: gibddValues } = await gibdd.getKPData(input); // TODO: remove this temp fix const quoteValues = shake({ @@ -38,6 +40,7 @@ const quoteRouter = t.router({ ...priceValues, ...bonusesValues, ...leasingObjectValues, + ...gibddValues, }); return {