diff --git a/apps/web/config/tables/insurance-table.ts b/apps/web/config/tables/insurance-table.ts index 89418f5..e737deb 100644 --- a/apps/web/config/tables/insurance-table.ts +++ b/apps/web/config/tables/insurance-table.ts @@ -33,31 +33,37 @@ export const defaultOptions: Record = { fingap: defaultRowOptions, }; +export const DEFAULT_OSAGO_ROW: Insurance.RowValues = { + key: 'osago', + policyType: 'ОСАГО', + insuranceCompany: null, + insured: 100_000_000, + insCost: 0, + insTerm: 100_000_000, +}; + +export const DEFAULT_KASKO_ROW: Insurance.RowValues = { + key: 'kasko', + policyType: 'КАСКО', + insuranceCompany: null, + insured: 100_000_000, + insCost: 0, + insTerm: null, +}; + +export const DEFAULT_FINGAP_ROW: Insurance.RowValues = { + key: 'fingap', + policyType: 'Safe Finance', + insuranceCompany: null, + insured: 100_000_000, + insCost: 0, + insTerm: null, +}; + export const defaultValues: Insurance.RowValues[] = [ - { - key: 'osago', - policyType: 'ОСАГО', - insuranceCompany: null, - insured: 100_000_000, - insCost: 0, - insTerm: 100_000_000, - }, - { - key: 'kasko', - policyType: 'КАСКО', - insuranceCompany: null, - insured: 100_000_000, - insCost: 0, - insTerm: null, - }, - { - key: 'fingap', - policyType: 'Safe Finance', - insuranceCompany: null, - insured: 100_000_000, - insCost: 0, - insTerm: null, - }, + DEFAULT_OSAGO_ROW, + DEFAULT_KASKO_ROW, + DEFAULT_FINGAP_ROW, ]; export const defaultStatuses: Record = { diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 3351e00..d3aa73f 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -419,7 +419,7 @@ export type GetQuoteFingapDataQueryVariables = Exact<{ }>; -export type GetQuoteFingapDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_fingap_accountid: string | null, evo_fingap_payer: number | null, evo_fingap_period: number | null, evo_product_risks: Array<{ __typename?: 'evo_product_risk', evo_addproduct_typeid: string | null } | null> | null } | null }; +export type GetQuoteFingapDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_product_risks: Array<{ __typename?: 'evo_product_risk', evo_addproduct_typeid: string | null } | null> | null } | null }; export type GetFinGapAddProductTypesQueryVariables = Exact<{ currentDate: InputMaybe; @@ -449,6 +449,13 @@ export type GetInsuranceDataQueryVariables = Exact<{ export type GetInsuranceDataQuery = { __typename?: 'Query', osago: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, kasko: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, fingap: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null }; +export type GetQuoteInsuranceDataQueryVariables = Exact<{ + quoteId: Scalars['Uuid']; +}>; + + +export type GetQuoteInsuranceDataQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_osago_accountid: string | null, evo_osago_payer: number | null, evo_osago_price: number | null, evo_kasko_accountid: string | null, evo_kasko_payer: number | null, evo_kasko_price: number | null, evo_insurance_period: number | null, evo_fingap_accountid: string | null, evo_fingap_payer: number | null, evo_fingap_period: number | null } | null }; + export type GetLeadUrlQueryVariables = Exact<{ id: Scalars['Uuid']; }>; @@ -564,11 +571,12 @@ export const GetRegistrationTypesDocument = {"kind":"Document","definitions":[{" 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 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"}}]}}]}}]} 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_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 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_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 GetQuoteInsuranceDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteInsuranceData"},"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_osago_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_osago_payer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_osago_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_payer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_insurance_period"}},{"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"}}]}}]}}]} 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; export const GetQuoteUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteUrl"},"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":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"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/bonuses/get-kp-data.ts b/apps/web/process/bonuses/get-kp-data.ts index b0ba0f8..249845c 100644 --- a/apps/web/process/bonuses/get-kp-data.ts +++ b/apps/web/process/bonuses/get-kp-data.ts @@ -1,4 +1,4 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +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'; @@ -12,13 +12,9 @@ const QUERY_GET_QUOTE_BONUS_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/configurator/get-kp-data.ts b/apps/web/process/configurator/get-kp-data.ts index b00611b..a440c94 100644 --- a/apps/web/process/configurator/get-kp-data.ts +++ b/apps/web/process/configurator/get-kp-data.ts @@ -1,4 +1,4 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types'; import initializeApollo from '@/apollo/client'; import * as CRMTypes from '@/graphql/crm.types'; import { gql } from '@apollo/client'; @@ -11,13 +11,9 @@ const QUERY_GET_QUOTE_CONFIGURATOR_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/fingap/get-kp-data.ts b/apps/web/process/fingap/get-kp-data.ts index 5498d10..afed1d8 100644 --- a/apps/web/process/fingap/get-kp-data.ts +++ b/apps/web/process/fingap/get-kp-data.ts @@ -1,18 +1,12 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types'; import initializeApollo from '@/apollo/client'; -import { defaultValues } from '@/config/tables/insurance-table'; import * 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_QUOTE_FINGAP_DATA = gql` query GetQuoteFingapData($quoteId: Uuid!) { quote(quoteId: $quoteId) { - evo_fingap_accountid - evo_fingap_payer - evo_fingap_period evo_product_risks { evo_addproduct_typeid } @@ -20,16 +14,9 @@ const QUERY_GET_QUOTE_FINGAP_DATA = gql` } `; -type OutputData = { - fingap: GetQuoteOutputData['fingap']; - insurance: { - values: Pick; - }; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { @@ -52,15 +39,5 @@ export async function getKPData({ 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, - }, - }, - }, }; } diff --git a/apps/web/process/gibdd/get-kp-data.ts b/apps/web/process/gibdd/get-kp-data.ts index 08e72a9..ca6975c 100644 --- a/apps/web/process/gibdd/get-kp-data.ts +++ b/apps/web/process/gibdd/get-kp-data.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types'; import helper from './lib/helper'; import initializeApollo from '@/apollo/client'; import defaultValues from '@/config/default-values'; @@ -29,11 +29,7 @@ const QUERY_GET_QUOTE_GIBDD_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - -export async function getKPData({ values }: GetQuoteInputData): Promise { +export async function getKPData({ values }: GetQuoteInputData): Promise { const { quote: quoteId, recalcWithRevision, lead: leadId, opportunity: opportunityId } = values; const apolloClient = initializeApollo(); diff --git a/apps/web/process/insurance/get-kp-data.ts b/apps/web/process/insurance/get-kp-data.ts new file mode 100644 index 0000000..74ca1b8 --- /dev/null +++ b/apps/web/process/insurance/get-kp-data.ts @@ -0,0 +1,64 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types'; +import initializeApollo from '@/apollo/client'; +import * as insuranceTable from '@/config/tables/insurance-table'; +import * as CRMTypes from '@/graphql/crm.types'; +import { gql } from '@apollo/client'; + +const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable; + +const QUERY_GET_QUOTE_INSURANCE_DATA = gql` + query GetQuoteInsuranceData($quoteId: Uuid!) { + quote(quoteId: $quoteId) { + evo_osago_accountid + evo_osago_payer + evo_osago_price + evo_kasko_accountid + evo_kasko_payer + evo_kasko_price + evo_insurance_period + evo_fingap_accountid + evo_fingap_payer + evo_fingap_period + } + } +`; + +export async function getKPData({ + values: { quote: quoteId }, +}: GetQuoteInputData): Promise { + const apolloClient = initializeApollo(); + + const { + data: { quote }, + } = await apolloClient.query({ + query: CRMTypes.GetQuoteInsuranceDataDocument, + variables: { + quoteId, + }, + }); + + return { + insurance: { + values: { + fingap: Object.assign(DEFAULT_FINGAP_ROW, { + insTerm: quote?.evo_fingap_period, + insuranceCompany: quote?.evo_fingap_accountid, + insured: quote?.evo_fingap_payer, + }), + kasko: Object.assign(DEFAULT_KASKO_ROW, { + insCost: quote?.evo_kasko_price, + insTerm: quote?.evo_insurance_period, + insuranceCompany: quote?.evo_kasko_accountid, + insured: quote?.evo_kasko_payer, + }), + osago: Object.assign(DEFAULT_OSAGO_ROW, { + insCost: quote?.evo_osago_price, + insTerm: quote?.evo_insurance_period, + insuranceCompany: quote?.evo_osago_accountid, + insured: quote?.evo_osago_payer, + }), + }, + }, + }; +} diff --git a/apps/web/process/insurance/index.ts b/apps/web/process/insurance/index.ts new file mode 100644 index 0000000..f5291d5 --- /dev/null +++ b/apps/web/process/insurance/index.ts @@ -0,0 +1 @@ +export * from './get-kp-data'; diff --git a/apps/web/process/leasing-object/get-kp-data.ts b/apps/web/process/leasing-object/get-kp-data.ts index 7fa052d..d6f1db9 100644 --- a/apps/web/process/leasing-object/get-kp-data.ts +++ b/apps/web/process/leasing-object/get-kp-data.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +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'; @@ -33,13 +33,9 @@ const QUERY_GET_QUOTE_LEASING_OBJECT_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId, recalcWithRevision }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/load-kp/reactions.ts b/apps/web/process/load-kp/reactions.ts index d4cd265..60b89e9 100644 --- a/apps/web/process/load-kp/reactions.ts +++ b/apps/web/process/load-kp/reactions.ts @@ -1,5 +1,4 @@ import type { ProcessContext } from '@/process/types'; -import extend from '@/stores/tables/insurance/tools'; import { reaction } from 'mobx'; import message from 'ui/elements/message'; @@ -48,13 +47,13 @@ export function common({ store, trpcClient }: ProcessContext) { $tables.payments.setValues(payments.values); if (insurance.values.osago) { - extend($tables.insurance).setRowValues(insurance.values.osago); + $tables.insurance.row('osago').setValues(insurance.values.osago); } if (insurance.values.kasko) { - extend($tables.insurance).setRowValues(insurance.values.kasko); + $tables.insurance.row('kasko').setValues(insurance.values.kasko); } if (insurance.values.fingap) { - extend($tables.insurance).setRowValues(insurance.values.fingap); + $tables.insurance.row('fingap').setValues(insurance.values.fingap); } if (fingap) $tables.fingap.setSelectedKeys(fingap.keys); diff --git a/apps/web/process/load-kp/types.ts b/apps/web/process/load-kp/types.ts index f47dd2a..c892dc2 100644 --- a/apps/web/process/load-kp/types.ts +++ b/apps/web/process/load-kp/types.ts @@ -32,11 +32,21 @@ const InsuranceSchema = z.object({ export const GetQuoteOutputDataSchema = z .object({ - fingap: FinGAPSchema.optional(), - insurance: InsuranceSchema.required(), + fingap: FinGAPSchema, + insurance: InsuranceSchema, payments: PaymentsSchema, values: ValuesSchema, }) .strict(); export type GetQuoteOutputData = z.infer; + +export const GetQuoteProcessDataSchema = GetQuoteOutputDataSchema.omit({ + values: true, +}) + .extend({ + values: ValuesSchema.partial(), + }) + .partial(); + +export type GetQuoteProcessData = z.infer; diff --git a/apps/web/process/payments/get-kp-data.ts b/apps/web/process/payments/get-kp-data.ts index 5e674fa..5124901 100644 --- a/apps/web/process/payments/get-kp-data.ts +++ b/apps/web/process/payments/get-kp-data.ts @@ -1,4 +1,4 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +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'; @@ -27,14 +27,9 @@ const QUERY_GET_QUOTE_PAYMENTS_DATA = gql` } `; -type OutputData = { - payments: GetQuoteOutputData['payments']; - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId, recalcWithRevision }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/price/get-kp-data.ts b/apps/web/process/price/get-kp-data.ts index ac384d4..14c3f8e 100644 --- a/apps/web/process/price/get-kp-data.ts +++ b/apps/web/process/price/get-kp-data.ts @@ -1,4 +1,4 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +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'; @@ -23,13 +23,9 @@ const QUERY_GET_QUOTE_PRICE_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/subsidy/get-kp-data.ts b/apps/web/process/subsidy/get-kp-data.ts index 3f64921..11e616f 100644 --- a/apps/web/process/subsidy/get-kp-data.ts +++ b/apps/web/process/subsidy/get-kp-data.ts @@ -1,4 +1,4 @@ -import type { GetQuoteInputData, GetQuoteOutputData } from '../load-kp/types'; +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'; @@ -13,13 +13,9 @@ const QUERY_GET_QUOTE_SUBSIDY_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/process/supplier-agent/get-kp-data/index.ts b/apps/web/process/supplier-agent/get-kp-data/index.ts index e571450..2845b9a 100644 --- a/apps/web/process/supplier-agent/get-kp-data/index.ts +++ b/apps/web/process/supplier-agent/get-kp-data/index.ts @@ -1,5 +1,5 @@ /* eslint-disable canonical/sort-keys */ -import type { GetQuoteInputData, GetQuoteOutputData } from '../../load-kp/types'; +import type { GetQuoteInputData, GetQuoteProcessData } from '../../load-kp/types'; import getSums from './get-sums'; import initializeApollo from '@/apollo/client'; import defaultValues from '@/config/default-values'; @@ -38,13 +38,9 @@ const QUERY_GET_QUOTE_AGENTS_DATA = gql` } `; -type OutputData = { - values: Partial; -}; - export async function getKPData({ values: { quote: quoteId }, -}: GetQuoteInputData): Promise { +}: GetQuoteInputData): Promise { const apolloClient = initializeApollo(); const { diff --git a/apps/web/stores/tables/insurance/index.ts b/apps/web/stores/tables/insurance/index.ts index b082e03..b79a33c 100644 --- a/apps/web/stores/tables/insurance/index.ts +++ b/apps/web/stores/tables/insurance/index.ts @@ -118,6 +118,12 @@ export default class InsuranceTable { return this.row(key); }, + setValues: (row: Insurance.RowValues) => { + (Object.keys(row) as Insurance.Values[]).forEach((valueName) => { + this.row(row.key).setValue(valueName, row[valueName]); + }); + }, + unblock: (valueName: Insurance.Values) => { this.statuses[key][valueName] = 'Default'; diff --git a/apps/web/stores/tables/insurance/tools.ts b/apps/web/stores/tables/insurance/tools.ts deleted file mode 100644 index d873e37..0000000 --- a/apps/web/stores/tables/insurance/tools.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type InsuranceTable from '.'; -import type * as Insurance from '@/Components/Calculation/Form/Insurance/InsuranceTable/types'; - -export default function extend(insuranceTable: InsuranceTable) { - return { - setRowValues(row: Insurance.RowValues) { - (Object.keys(row) as Insurance.Values[]).forEach((valueName) => { - insuranceTable.row(row.key).setValue(valueName, row[valueName]); - }); - }, - }; -} diff --git a/apps/web/trpc/routers/quote.ts b/apps/web/trpc/routers/quote.ts index 0cded9e..1d1d794 100644 --- a/apps/web/trpc/routers/quote.ts +++ b/apps/web/trpc/routers/quote.ts @@ -1,11 +1,13 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable canonical/sort-keys */ import { t } from '../server'; import defaultValues from '@/config/default-values'; -import { defaultValues as defaultInsuranceValues } from '@/config/tables/insurance-table'; +import * as insuranceTable from '@/config/tables/insurance-table'; 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 insuranceProcess from '@/process/insurance'; import * as leasingObject from '@/process/leasing-object'; import * as loadKP from '@/process/load-kp'; import * as paymentsProcess from '@/process/payments'; @@ -13,49 +15,49 @@ import * as price from '@/process/price'; import * as subsidy from '@/process/subsidy'; import * as supplierAgent from '@/process/supplier-agent'; -const DEFAULT_OSAGO_ROW = defaultInsuranceValues.find((x) => x.key === 'osago'); -const DEFAULT_KASKO_ROW = defaultInsuranceValues.find((x) => x.key === 'kasko'); +const { GetQuoteInputDataSchema, GetQuoteOutputDataSchema } = loadKP; +const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable; -const { - GetQuoteInputDataSchema: GetQuoteDataInputSchema, - GetQuoteOutputDataSchema: GetQuoteDataOutputSchema, -} = loadKP; +const defaultInsurance = { + values: { + fingap: DEFAULT_FINGAP_ROW, + kasko: DEFAULT_KASKO_ROW, + osago: DEFAULT_OSAGO_ROW, + }, +}; + +const defaultFingap = { keys: [] }; +const defaultPayments = { values: [] }; const quoteRouter = t.router({ getData: t.procedure - .input(GetQuoteDataInputSchema) - .output(GetQuoteDataOutputSchema) + .input(GetQuoteInputDataSchema) + .output(GetQuoteOutputDataSchema) .query(async ({ input }) => { - const { values: configuratorValues } = await configurator.getKPData(input); - const { values: supplierAgentsValues } = await supplierAgent.getKPData(input); - const { values: paymentsValues, payments } = await paymentsProcess.getKPData(input); - const { values: priceValues } = await price.getKPData(input); - 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); - const { values: subsidyValues } = await subsidy.getKPData(input); + const output = await Promise.all( + [ + configurator, + supplierAgent, + paymentsProcess, + price, + bonuses, + leasingObject, + fingapProcess, + gibdd, + subsidy, + insuranceProcess, + ].map(({ getKPData }) => getKPData(input)) + ); + + const values = output.reduce((obj, data) => Object.assign(obj, data.values), defaultValues); + const payments = output.find((x) => x.payments)?.payments ?? defaultPayments; + const insurance = output.find((x) => x.insurance)?.insurance ?? defaultInsurance; + const fingap = output.find((x) => x.fingap)?.fingap ?? defaultFingap; return { - values: { - ...defaultValues, - ...configuratorValues, - ...supplierAgentsValues, - ...paymentsValues, - ...priceValues, - ...bonusesValues, - ...leasingObjectValues, - ...gibddValues, - ...subsidyValues, - }, + values, payments, - insurance: { - values: { - osago: DEFAULT_OSAGO_ROW, - kasko: DEFAULT_KASKO_ROW, - fingap: fingapInsurance.values.fingap, - }, - }, + insurance, fingap, }; }),