From 70d5386b15f43c6b894c47fe67568bd00685feb3 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 6 Feb 2024 14:16:15 +0300 Subject: [PATCH] apps/web: move getTarif usage to server --- apps/web/graphql/crm.query.graphql | 2 ++ apps/web/graphql/crm.types.ts | 4 ++-- apps/web/process/configurator/lib/helper.ts | 2 +- .../process/configurator/reactions/values.ts | 14 ++++++++----- apps/web/process/hooks/init/get-main-data.js | 20 +++++++++---------- apps/web/server/routers/_app.ts | 3 ++- apps/web/server/routers/tarif/index.ts | 14 +++++++++++++ apps/web/server/routers/tarif/types.ts | 16 +++++++++++++++ 8 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 apps/web/server/routers/tarif/index.ts create mode 100644 apps/web/server/routers/tarif/types.ts diff --git a/apps/web/graphql/crm.query.graphql b/apps/web/graphql/crm.query.graphql index 1d1e6c9..04c01d3 100644 --- a/apps/web/graphql/crm.query.graphql +++ b/apps/web/graphql/crm.query.graphql @@ -139,6 +139,8 @@ query GetTarifs($currentDate: DateTime) { query GetTarif($tarifId: Uuid!) { evo_tarif(evo_tarifid: $tarifId) { + label: evo_name + value: evo_tarifid evo_irr evo_graphtype_exception evo_seasons_type_exception diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 923de21..244d522 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -777,7 +777,7 @@ export type GetTarifQueryVariables = Exact<{ }>; -export type GetTarifQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array | null, evo_seasons_type_exception: Array | null, evo_min_decreasing_perc: number | null, evo_min_irr: number | null, evo_cut_irr_with_bonus_coefficient: number | null, evo_max_irr: number | null, evo_irr_plan: number | null, evo_margin_min: number | null, evo_rates: Array<{ __typename?: 'evo_rate', evo_datefrom: string | null, evo_rateid: string | null } | null> | null } | null }; +export type GetTarifQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array | null, evo_seasons_type_exception: Array | null, evo_min_decreasing_perc: number | null, evo_min_irr: number | null, evo_cut_irr_with_bonus_coefficient: number | null, evo_max_irr: number | null, evo_irr_plan: number | null, evo_margin_min: number | null, label: string | null, value: string | null, evo_rates: Array<{ __typename?: 'evo_rate', evo_datefrom: string | null, evo_rateid: string | null } | null> | null } | null }; export type GetRatesQueryVariables = Exact<{ currentDate: InputMaybe; @@ -1208,7 +1208,7 @@ export const GetOpportunitiesDocument = {"kind":"Document","definitions":[{"kind export const GetQuotesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuotes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quotes"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_quotename"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"quoteid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_recalc_limit"}},{"kind":"Field","name":{"kind":"Name","value":"evo_statuscodeidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_purchases_participation"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuote"},"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_one_year_insurance"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_change_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_price_change"}},{"kind":"Field","name":{"kind":"Name","value":"evo_discount_supplier_currency"}},{"kind":"Field","name":{"kind":"Name","value":"evo_equip_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_program_import_subsidy_sum"}},{"kind":"Field","name":{"kind":"Name","value":"evo_nds_in_price_supplier_currency"}},{"kind":"Field","name":{"kind":"Name","value":"evo_supplier_currency_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_approved_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_recalc_limit"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_mass"}},{"kind":"Field","name":{"kind":"Name","value":"evo_seats"}},{"kind":"Field","name":{"kind":"Name","value":"evo_year"}},{"kind":"Field","name":{"kind":"Name","value":"evo_last_payment_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_maximum_percentage_av"}},{"kind":"Field","name":{"kind":"Name","value":"evo_untype_insurance"}},{"kind":"Field","name":{"kind":"Name","value":"evo_percent_subsidy"}},{"kind":"Field","name":{"kind":"Name","value":"evo_programsolution"}},{"kind":"Field","name":{"kind":"Name","value":"evo_kasko_payer"}},{"kind":"Field","name":{"kind":"Name","value":"evo_promotion"}},{"kind":"Field","name":{"kind":"Name","value":"evo_sale_without_nds"}}]}}]}}]} as unknown as DocumentNode; export const GetTarifsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarifs"},"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_tarifs"},"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_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_delivery_time"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_used"}},{"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_pl_use_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_nds_rules"}},{"kind":"Field","name":{"kind":"Name","value":"evo_floating_rate"}}]}}]}}]} as unknown as DocumentNode; -export const GetTarifDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarif"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarif"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_tarifid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graphtype_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_seasons_type_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_decreasing_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cut_irr_with_bonus_coefficient"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_rates"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_datefrom"}},{"kind":"Field","name":{"kind":"Name","value":"evo_rateid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_irr_plan"}},{"kind":"Field","name":{"kind":"Name","value":"evo_margin_min"}}]}}]}}]} as unknown as DocumentNode; +export const GetTarifDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarif"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarif"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_tarifid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"tarifId"}}}],"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_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graphtype_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_seasons_type_exception"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_decreasing_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cut_irr_with_bonus_coefficient"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_irr"}},{"kind":"Field","name":{"kind":"Name","value":"evo_rates"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_datefrom"}},{"kind":"Field","name":{"kind":"Name","value":"evo_rateid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_irr_plan"}},{"kind":"Field","name":{"kind":"Name","value":"evo_margin_min"}}]}}]}}]} as unknown as DocumentNode; export const GetRatesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRates"},"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_rates"},"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_rateid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_tarifs"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarifid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_rateid"}}]}}]}}]} as unknown as DocumentNode; export const GetRateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRate"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"rateId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_rate"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_rateid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"rateId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_base_rate"}},{"kind":"Field","name":{"kind":"Name","value":"evo_credit_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_finance_rate"}}]}}]}}]} as unknown as DocumentNode; export const GetProductsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetProducts"},"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_baseproducts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_relation"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000000"}]}},{"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_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"systemusers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemuserid"}}]}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/configurator/lib/helper.ts b/apps/web/process/configurator/lib/helper.ts index c149189..f773a2d 100644 --- a/apps/web/process/configurator/lib/helper.ts +++ b/apps/web/process/configurator/lib/helper.ts @@ -208,7 +208,7 @@ export default function helper({ apolloClient }: Pick $process.has('LoadKP'), @@ -30,10 +30,14 @@ export default function valuesReactions({ store, apolloClient }: ProcessContext) 'partialVAT', ]), async (values) => { - const { evo_tarif, evo_tarifs } = await getTarifs(values); + const { evo_tarif } = await trpcClient.getTarif.query(values); - $calculation.element('selectTarif').setOptions(normalizeOptions(evo_tarifs)).resetValue(); - $calculation.element('selectTarif').setValue(evo_tarif?.evo_tarifid || null); + if (evo_tarif) { + $calculation.element('selectTarif').setOptions(normalizeOptions([evo_tarif])); + $calculation.element('selectTarif').setValue(evo_tarif.evo_tarifid); + } else { + $calculation.element('selectTarif').resetOptions(); + } }, { delay: 10, diff --git a/apps/web/process/hooks/init/get-main-data.js b/apps/web/process/hooks/init/get-main-data.js index 4737406..67d69a1 100644 --- a/apps/web/process/hooks/init/get-main-data.js +++ b/apps/web/process/hooks/init/get-main-data.js @@ -113,16 +113,16 @@ function getMainData({ query }, onCompleted) { onCompleted({ selectInsNSIB: data?.evo_addproduct_types }); }); - query({ - query: CRMTypes.GetTarifsDocument, - variables: { - currentDate, - }, - }).then(({ data }) => { - onCompleted({ - selectTarif: data?.evo_tarifs, - }); - }); + // query({ + // query: CRMTypes.GetTarifsDocument, + // variables: { + // currentDate, + // }, + // }).then(({ data }) => { + // onCompleted({ + // selectTarif: data?.evo_tarifs, + // }); + // }); } export function useMainData() { diff --git a/apps/web/server/routers/_app.ts b/apps/web/server/routers/_app.ts index 2100bc5..160ddb4 100644 --- a/apps/web/server/routers/_app.ts +++ b/apps/web/server/routers/_app.ts @@ -1,7 +1,8 @@ import { mergeRouters } from '../trpc'; import { calculateRouter } from './calculate'; import { quoteRouter } from './quote'; +import { tarifRouter } from './tarif'; -export const appRouter = mergeRouters(quoteRouter, calculateRouter); +export const appRouter = mergeRouters(quoteRouter, calculateRouter, tarifRouter); export type AppRouter = typeof appRouter; diff --git a/apps/web/server/routers/tarif/index.ts b/apps/web/server/routers/tarif/index.ts new file mode 100644 index 0000000..94236b9 --- /dev/null +++ b/apps/web/server/routers/tarif/index.ts @@ -0,0 +1,14 @@ +import { protectedProcedure } from '../../procedure'; +import { router } from '../../trpc'; +import { GetTarifInputSchema } from './types'; +import initializeApollo from '@/apollo/client'; +import configuratorHelper from '@/process/configurator/lib/helper'; + +export const tarifRouter = router({ + getTarif: protectedProcedure.input(GetTarifInputSchema).query(async ({ input }) => { + const apolloClient = initializeApollo(); + const { getTarifs } = configuratorHelper({ apolloClient }); + + return getTarifs(input); + }), +}); diff --git a/apps/web/server/routers/tarif/types.ts b/apps/web/server/routers/tarif/types.ts new file mode 100644 index 0000000..bf11601 --- /dev/null +++ b/apps/web/server/routers/tarif/types.ts @@ -0,0 +1,16 @@ +import ValuesSchema from '@/config/schema/values'; +import type { z } from 'zod'; + +export const GetTarifInputSchema = ValuesSchema.pick({ + deliveryTime: true, + firstPaymentPerc: true, + floatingRate: true, + lastPaymentPerc: true, + leaseObjectType: true, + leaseObjectUsed: true, + leasingPeriod: true, + partialVAT: true, + product: true, +}); + +export type GetTarifInput = z.infer;