From 9c3fa098b8d373ccb45528845c597ee90c4def3c Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 29 Mar 2023 18:49:34 +0300 Subject: [PATCH] create-kp: add get values from kp store/calculation/values: fix setValues method --- apps/web/graphql/crm.types.ts | 8 +++ apps/web/process/create-kp/get-kp-data.ts | 55 +++++++++++++++++++++ apps/web/process/create-kp/index.ts | 1 + apps/web/server/routers/quote/index.ts | 2 + apps/web/stores/calculation/values/index.ts | 4 +- 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 apps/web/process/create-kp/get-kp-data.ts diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 4ea012a..fd58714 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -498,6 +498,13 @@ export type GetQuoteConfiguratorDataQueryVariables = Exact<{ export type GetQuoteConfiguratorDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_baseproductid: string | null, evo_client_typeid: string | null, evo_msfo_irr: number | null } | null }; +export type GetQuoteCreateKpDataQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetQuoteCreateKpDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_price_with_discount: boolean | null, evo_price_without_discount_quote: boolean | null, evo_cost_increace: boolean | null, evo_insurance: boolean | null, evo_registration_quote: boolean | null, evo_card_quote: boolean | null, evo_nsib_quote: boolean | null, evo_redemption_graph: boolean | null, evo_fingap_quote: boolean | null, evo_contact_name: string | null, evo_gender: number | null } | null }; + export type GetQuoteFingapDataQueryVariables = Exact<{ quoteId: Scalars['Uuid']; }>; @@ -653,6 +660,7 @@ export const GetRolesDocument = {"kind":"Document","definitions":[{"kind":"Opera export const GetQuoteAddProductDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteAddProductData"},"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_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteBonusDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteBonusData"},"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 GetQuoteConfiguratorDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteConfiguratorData"},"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"}},{"kind":"Field","name":{"kind":"Name","value":"evo_client_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_msfo_irr"}}]}}]}}]} as unknown as DocumentNode; +export const GetQuoteCreateKpDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteCreateKPData"},"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_price_with_discount"}},{"kind":"Field","name":{"kind":"Name","value":"evo_price_without_discount_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_increace"}},{"kind":"Field","name":{"kind":"Name","value":"evo_insurance"}},{"kind":"Field","name":{"kind":"Name","value":"evo_registration_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_card_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_nsib_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_redemption_graph"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fingap_quote"}},{"kind":"Field","name":{"kind":"Name","value":"evo_contact_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_gender"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteFingapDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteFingapData"},"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_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 GetQuoteGibddDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteGibddData"},"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_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"}},{"kind":"Field","name":{"kind":"Name","value":"evo_req_telematic"}},{"kind":"Field","name":{"kind":"Name","value":"evo_req_telematic_accept"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/create-kp/get-kp-data.ts b/apps/web/process/create-kp/get-kp-data.ts new file mode 100644 index 0000000..249b86e --- /dev/null +++ b/apps/web/process/create-kp/get-kp-data.ts @@ -0,0 +1,55 @@ +import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types'; +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_CREATEKP_DATA = gql` + query GetQuoteCreateKPData($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_price_with_discount + evo_price_without_discount_quote + evo_cost_increace + evo_insurance + evo_registration_quote + evo_card_quote + evo_nsib_quote + evo_redemption_graph + evo_fingap_quote + evo_contact_name + evo_gender + } + } +`; + +export async function getKPData({ + values: { quote: quoteId }, +}: GetQuoteInputData): Promise { + const apolloClient = initializeApollo(); + + const { + data: { quote }, + } = await apolloClient.query({ + query: CRMTypes.GetQuoteCreateKpDataDocument, + variables: { + quoteId, + }, + }); + + return { + values: { + NSIB: quote?.evo_nsib_quote ?? defaultValues.NSIB, + costIncrease: quote?.evo_cost_increace ?? defaultValues.costIncrease, + fullPriceWithDiscount: + quote?.evo_price_without_discount_quote ?? defaultValues.fullPriceWithDiscount, + insurance: quote?.evo_insurance ?? defaultValues.insurance, + priceWithDiscount: quote?.evo_price_with_discount ?? defaultValues.priceWithDiscount, + quoteContactGender: quote?.evo_gender ?? defaultValues.quoteContactGender, + quoteName: quote?.evo_contact_name ?? defaultValues.quoteName, + quoteRedemptionGraph: quote?.evo_redemption_graph ?? defaultValues.quoteRedemptionGraph, + registrationQuote: quote?.evo_registration_quote ?? defaultValues.registrationQuote, + showFinGAP: quote?.evo_fingap_quote ?? defaultValues.showFinGAP, + technicalCardQuote: quote?.evo_card_quote ?? defaultValues.technicalCardQuote, + }, + }; +} diff --git a/apps/web/process/create-kp/index.ts b/apps/web/process/create-kp/index.ts index facb8da..3299eac 100644 --- a/apps/web/process/create-kp/index.ts +++ b/apps/web/process/create-kp/index.ts @@ -1,2 +1,3 @@ export * from './action'; +export * from './get-kp-data'; export * as reactions from './reactions'; diff --git a/apps/web/server/routers/quote/index.ts b/apps/web/server/routers/quote/index.ts index 3f29522..463d8b1 100644 --- a/apps/web/server/routers/quote/index.ts +++ b/apps/web/server/routers/quote/index.ts @@ -21,6 +21,7 @@ import * as CRMTypes from '@/graphql/crm.types'; import * as addProduct from '@/process/add-product'; import * as bonuses from '@/process/bonuses'; import * as configurator from '@/process/configurator'; +import * as createKpProcess from '@/process/create-kp'; import * as fingapProcess from '@/process/fingap'; import * as gibdd from '@/process/gibdd'; import * as insuranceProcess from '@/process/insurance'; @@ -63,6 +64,7 @@ export const quoteRouter = router({ subsidy, insuranceProcess, addProduct, + createKpProcess, ].map(({ getKPData }) => getKPData(input)) ); diff --git a/apps/web/stores/calculation/values/index.ts b/apps/web/stores/calculation/values/index.ts index 60ae3f1..15e738f 100644 --- a/apps/web/stores/calculation/values/index.ts +++ b/apps/web/stores/calculation/values/index.ts @@ -26,7 +26,9 @@ export default class ValuesStore { public setValues = (values: Partial) => { (Object.keys(values) as Array).forEach((valueName) => { const value = values[valueName]; - if (value) this.setValue(valueName, value); + if (value !== null && value !== undefined) { + this.setValue(valueName, value); + } }); };