server: combine miltiple quote query to single

This commit is contained in:
vchikalkin 2024-02-16 13:22:01 +03:00
parent c092b8f47c
commit 53debf2cff
18 changed files with 216 additions and 570 deletions

View File

@ -110,6 +110,158 @@ query GetQuote($quoteId: Uuid!) {
}
}
query GetQuoteData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_addproduct_types {
evo_product_type
evo_addproduct_typeid
}
evo_accept_control_addproduct_typeid
evo_sale_bonus
evo_baseproductid
evo_client_typeid
evo_msfo_irr
evo_delivery_time
evo_first_payment_perc
evo_last_payment_perc
evo_leasingobject_typeid
evo_leasingobject_used
evo_period
evo_accept_period
evo_rateid
evo_min_change_price
evo_max_price_change
evo_floating_rate
evo_sale_without_nds
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
evo_last_payment_redemption
evo_full_nds_price
evo_kasko_accountid
evo_kasko_price
evo_id_elt_kasko
evo_id_kasko_calc
evo_franchise
evo_osago_accountid
evo_id_elt_osago
evo_osago_price
evo_db_accept_registration
evo_object_registration
evo_pts_type
evo_vehicle_tax_year
evo_vehicle_tax_approved
evo_category_tr
evo_vehicle_type_tax
evo_regionid
evo_townid
evo_legal_regionid
evo_legal_townid
evo_registration_regionid
evo_req_telematic
evo_req_telematic_accept
evo_osago_payer
evo_kasko_payer
evo_insurance_period
evo_fingap_accountid
evo_fingap_payer
evo_fingap_period
evo_fingap_price
evo_gps_brandid
evo_gps_modelid
evo_insurance_decentral
evo_unlimit_drivers
evo_age_drivers
evo_exp_drivers
evo_brandid
evo_category
evo_engine_hours
evo_engine_type
evo_engine_volume
evo_equipmentid
evo_max_mass
evo_max_speed
evo_mileage
evo_modelid
evo_object_count
evo_power
evo_recalc_limit
evo_seats
evo_trailer
evo_use_for
evo_vin
evo_year
evo_graph_type
evo_payments_decrease_perc
evo_seasons_type
evo_high_season
evo_graphs {
createdon
evo_sumpay_withnds
evo_planpayments {
evo_payment_ratio
}
}
evo_subsidyid
evo_program_import_subsidyid
evo_supplier_accountid
evo_dealer_person_accountid
evo_dealer_reward_conditionid
evo_dealer_reward_total
evo_dealer_reward_summ
evo_dealer_broker_accountid
evo_dealer_broker_reward_conditionid
evo_dealer_broker_reward_total
evo_dealer_broker_reward_summ
evo_agent_accountid
evo_agent_reward_conditionid
evo_agent_reward_total
evo_agent_reward_summ
evo_double_agent_accountid
evo_double_agent_reward_conditionid
evo_double_agent_reward_total
evo_double_agent_reward_summ
evo_broker_accountid
evo_broker_reward_conditionid
evo_broker_reward_total
evo_broker_reward_summ
evo_fin_department_accountid
evo_fin_department_reward_conditionid
evo_fin_department_reward_total
evo_fin_department_reward_summ
evo_supplier_financing
evo_leadidData {
evo_agent_accountid
evo_double_agent_accountid
evo_broker_accountid
evo_fin_department_accountid
}
evo_product_risks {
evo_addproduct_typeid
}
evo_comission_rub
evo_comission_perc
evo_discount_perc
evo_discount_supplier_currency
evo_first_payment_rub
evo_last_payment_calc
evo_last_payment_rub
evo_nds_in_price_supplier_currency
evo_price_without_nds_supplier_currency
evo_supplier_currency_price
evo_transactioncurrencyid
evo_equip_price
}
}
query GetTarifs($currentDate: DateTime) {
evo_tarifs(
statecode: 0

File diff suppressed because one or more lines are too long

View File

@ -2,35 +2,13 @@ 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';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_ADD_PRODUCT_DATA = gql`
query GetQuoteAddProductData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_addproduct_types {
evo_product_type
evo_addproduct_typeid
}
evo_accept_control_addproduct_typeid
}
}
`;
export async function getKPData({
values: { quote: quoteId, recalcWithRevision },
values: { recalcWithRevision },
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteAddProductDataDocument,
variables: {
quoteId,
},
});
const registration =
quote?.evo_addproduct_types?.find((x) => x?.evo_product_type === 100_000_001)
?.evo_addproduct_typeid ?? defaultValues.registration;

View File

@ -1,31 +1,7 @@
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_QUOTE_BONUS_DATA = gql`
query GetQuoteBonusData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_sale_bonus
}
}
`;
export async function getKPData({
values: { quote: quoteId },
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteBonusDataDocument,
variables: {
quoteId,
},
});
export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteProcessData> {
return {
values: {
saleBonus: quote?.evo_sale_bonus ?? defaultValues.saleBonus,

View File

@ -4,49 +4,18 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import helper from './lib/helper';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { getKPData as getKPDataPrice } from '@/process/price/get-kp-data';
import { getKPData as getKPDataSubsidy } from '@/process/subsidy/get-kp-data';
import { createCurrencyUtility } from '@/utils/currency';
import { normalizeOptions } from '@/utils/entity';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_CONFIGURATOR_DATA = gql`
query GetQuoteConfiguratorData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_baseproductid
evo_client_typeid
evo_msfo_irr
evo_delivery_time
evo_first_payment_perc
evo_last_payment_perc
evo_leasingobject_typeid
evo_leasingobject_used
evo_period
evo_accept_period
evo_rateid
evo_min_change_price
evo_max_price_change
evo_floating_rate
evo_sale_without_nds
}
}
`;
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const { quote: quoteId, recalcWithRevision } = values;
export async function getKPData({
values,
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const { recalcWithRevision } = values;
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteConfiguratorDataDocument,
variables: {
quoteId,
},
});
const leasingPeriod = recalcWithRevision
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
: quote?.evo_period ?? 0;
@ -91,8 +60,8 @@ export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuote
let minPriceChange = quote?.evo_min_change_price ?? defaultValues.minPriceChange;
if (!recalcWithRevision) {
const kpDataPrice = await getKPDataPrice({ values });
const kpDataSubsidy = await getKPDataSubsidy({ values });
const kpDataPrice = await getKPDataPrice({ quote, values });
const kpDataSubsidy = await getKPDataSubsidy({ quote, values });
const supplierCurrency = kpDataPrice.values?.supplierCurrency ?? defaultValues.supplierCurrency;
const leaseObjectPrice = kpDataPrice.values?.leaseObjectPrice ?? defaultValues.leaseObjectPrice;

View File

@ -1,44 +1,7 @@
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';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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
evo_last_payment_redemption
evo_full_nds_price
}
}
`;
export async function getKPData({
values: { quote: quoteId },
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteCreateKpDataDocument,
variables: {
quoteId,
},
});
export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteProcessData> {
return {
values: {
NSIB: quote?.evo_nsib_quote ?? defaultValues.NSIB,

View File

@ -1,39 +1,6 @@
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';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_ELT_DATA = gql`
query GetQuoteEltData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_kasko_accountid
evo_kasko_price
evo_id_elt_kasko
evo_id_kasko_calc
evo_franchise
evo_osago_accountid
evo_id_elt_osago
evo_osago_price
evo_leasingobject_typeid
}
}
`;
export async function getKPData({
values: { quote: quoteId },
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteEltDataDocument,
variables: {
quoteId,
},
});
export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const elt: NonNullable<GetQuoteProcessData['elt']> = { kasko: undefined, osago: undefined };
if (

View File

@ -1,33 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
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';
const QUERY_GET_QUOTE_FINGAP_DATA = gql`
query GetQuoteFingapData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_product_risks {
evo_addproduct_typeid
}
}
}
`;
export async function getKPData({
values: { quote: quoteId },
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteFingapDataDocument,
variables: {
quoteId,
},
});
export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const keys: string[] = [];
quote?.evo_product_risks?.forEach((x) => {
if (x?.evo_addproduct_typeid) {

View File

@ -3,45 +3,15 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import helper from './lib/helper';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_GIBDD_DATA = gql`
query GetQuoteGibddData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_db_accept_registration
evo_object_registration
evo_pts_type
evo_vehicle_tax_year
evo_vehicle_tax_approved
evo_category_tr
evo_vehicle_type_tax
evo_regionid
evo_townid
evo_legal_regionid
evo_legal_townid
evo_registration_regionid
evo_req_telematic
evo_req_telematic_accept
}
}
`;
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const { quote: quoteId, recalcWithRevision, lead: leadId, opportunity: opportunityId } = values;
export async function getKPData({
values,
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const { recalcWithRevision, lead: leadId, opportunity: opportunityId } = values;
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteGibddDataDocument,
variables: {
quoteId,
},
});
const { getData } = helper({
apolloClient,
});

View File

@ -5,63 +5,27 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as insuranceTable from '@/config/tables/insurance-table';
import * as CRMTypes from '@/graphql/crm.types';
import { getKPData as getKPDataFingap } from '@/process/fingap/get-kp-data';
import { getKPData as getKPDataPayments } from '@/process/payments/get-kp-data';
import { getKPData as getKPDataPrice } from '@/process/price/get-kp-data';
import { createCurrencyUtility } from '@/utils/currency';
import { gql } from '@apollo/client';
import { QueryClient } from '@tanstack/react-query';
import { sum } from 'radash';
const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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
evo_fingap_price
evo_gps_brandid
evo_gps_modelid
evo_insurance_decentral
evo_franchise
evo_unlimit_drivers
evo_age_drivers
evo_exp_drivers
}
}
`;
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const { quote: quoteId } = values;
export async function getKPData({
values,
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const queryClient = new QueryClient();
const { getFingapRisks } = helper({ apolloClient, queryClient });
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteInsuranceDataDocument,
variables: {
quoteId,
},
});
const kpDataPrice = await getKPDataPrice({ values });
const kpDataPayments = await getKPDataPayments({ values });
const kpDataFingap = await getKPDataFingap({ values });
const kpDataPrice = await getKPDataPrice({ quote, values });
const kpDataPayments = await getKPDataPayments({ quote, values });
const kpDataFingap = await getKPDataFingap({ quote, values });
const leaseObjectPrice = kpDataPrice.values?.leaseObjectPrice ?? defaultValues.leaseObjectPrice;
const firstPaymentRub = kpDataPrice.values?.firstPaymentRub ?? defaultValues.firstPaymentRub;

View File

@ -2,52 +2,13 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import helper from './lib/helper';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_LEASING_OBJECT_DATA = gql`
query GetQuoteLeasingObjectData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_brandid
evo_category
evo_delivery_time
evo_engine_hours
evo_engine_type
evo_engine_volume
evo_equipmentid
evo_leasingobject_typeid
evo_leasingobject_used
evo_max_mass
evo_max_speed
evo_mileage
evo_modelid
evo_object_count
evo_power
evo_recalc_limit
evo_seats
evo_trailer
evo_use_for
evo_vin
evo_year
}
}
`;
export async function getKPData({
values: { quote: quoteId, recalcWithRevision },
values: { recalcWithRevision },
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteLeasingObjectDataDocument,
variables: {
quoteId,
},
});
const brand = quote?.evo_brandid ?? defaultValues.brand;
const model = quote?.evo_modelid ?? defaultValues.model;
const leaseObjectUsed = quote?.evo_leasingobject_used ?? defaultValues.leaseObjectUsed;

View File

@ -1,49 +1,13 @@
import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import { generateDegressionRows } from './lib/degression-tools';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { gql } from '@apollo/client';
import { sort } from 'radash';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_PAYMENTS_DATA = gql`
query GetQuotePaymentsData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_period
evo_accept_period
evo_first_payment_perc
evo_last_payment_perc
evo_graph_type
evo_payments_decrease_perc
evo_seasons_type
evo_high_season
evo_graphs {
createdon
evo_sumpay_withnds
evo_planpayments {
evo_payment_ratio
}
}
}
}
`;
// eslint-disable-next-line sonarjs/cognitive-complexity
export async function getKPData({
values: { quote: quoteId, recalcWithRevision },
values: { recalcWithRevision },
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuotePaymentsDataDocument,
variables: {
quoteId,
},
});
const leasingPeriod = recalcWithRevision
? Math.min(quote?.evo_period ?? 0, quote?.evo_accept_period ?? 0)
: quote?.evo_period ?? 0;

View File

@ -1,46 +1,11 @@
/* eslint-disable sonarjs/cognitive-complexity */
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';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_PRICE_DATA = gql`
query GetQuotePriceData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_comission_rub
evo_comission_perc
evo_discount_perc
evo_discount_supplier_currency
evo_first_payment_perc
evo_first_payment_rub
evo_last_payment_calc
evo_last_payment_perc
evo_last_payment_rub
evo_nds_in_price_supplier_currency
evo_price_without_nds_supplier_currency
evo_supplier_currency_price
evo_transactioncurrencyid
evo_equip_price
}
}
`;
export async function getKPData({
values: { quote: quoteId, recalcWithRevision },
values: { recalcWithRevision },
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuotePriceDataDocument,
variables: {
quoteId,
},
});
let lastPaymentRule = quote?.evo_last_payment_calc ?? defaultValues.lastPaymentRule;
if (recalcWithRevision && quote?.evo_last_payment_calc === 100_000_002) {

View File

@ -2,36 +2,16 @@ import type { GetQuoteInputData, GetQuoteProcessData } from '../load-kp/types';
import helper from './lib/helper';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { getKPData as getKPDataPrice } from '@/process/price/get-kp-data';
import { createCurrencyUtility } from '@/utils/currency';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_SUBSIDY_DATA = gql`
query GetQuoteSubsidyData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_subsidyid
evo_program_import_subsidyid
}
}
`;
export async function getKPData({ values }: GetQuoteInputData): Promise<GetQuoteProcessData> {
export async function getKPData({
values,
quote,
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const { quote: quoteId } = values;
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteSubsidyDataDocument,
variables: {
quoteId,
},
});
const kpDataPrice = await getKPDataPrice({ values });
const kpDataPrice = await getKPDataPrice({ quote, values });
const { RUB } = createCurrencyUtility({ apolloClient });
const supplierCurrency = kpDataPrice.values?.supplierCurrency ?? defaultValues.supplierCurrency;

View File

@ -2,7 +2,7 @@ import initializeApollo from '@/apollo/client';
import type * as CRMTypes from '@/graphql/crm.types';
import { gql } from '@apollo/client';
type Quote = NonNullable<CRMTypes.GetQuoteAgentsDataQuery['quote']>;
type Quote = NonNullable<CRMTypes.GetQuoteDataQuery['quote']>;
const QUERY_GET_REWARD_RULES = gql`
query GetRewardRules($conditionId: Uuid!) {

View File

@ -1,65 +1,9 @@
/* eslint-disable canonical/sort-keys */
import type { GetQuoteInputData, GetQuoteProcessData } from '../../load-kp/types';
import getSums from './get-sums';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as CRMTypes from '@/graphql/crm.types';
import { gql } from '@apollo/client';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const QUERY_GET_QUOTE_AGENTS_DATA = gql`
query GetQuoteAgentsData($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_supplier_accountid
evo_dealer_person_accountid
evo_dealer_reward_conditionid
evo_dealer_reward_total
evo_dealer_reward_summ
evo_dealer_broker_accountid
evo_dealer_broker_reward_conditionid
evo_dealer_broker_reward_total
evo_dealer_broker_reward_summ
evo_agent_accountid
evo_agent_reward_conditionid
evo_agent_reward_total
evo_agent_reward_summ
evo_double_agent_accountid
evo_double_agent_reward_conditionid
evo_double_agent_reward_total
evo_double_agent_reward_summ
evo_broker_accountid
evo_broker_reward_conditionid
evo_broker_reward_total
evo_broker_reward_summ
evo_fin_department_accountid
evo_fin_department_reward_conditionid
evo_fin_department_reward_total
evo_fin_department_reward_summ
evo_supplier_financing
evo_leadidData {
evo_agent_accountid
evo_double_agent_accountid
evo_broker_accountid
evo_fin_department_accountid
}
}
}
`;
export async function getKPData({
values: { quote: quoteId },
}: GetQuoteInputData): Promise<GetQuoteProcessData> {
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteAgentsDataDocument,
variables: {
quoteId,
},
});
export async function getKPData({ quote }: GetQuoteInputData): Promise<GetQuoteProcessData> {
const sums = await getSums(quote);
return {

View File

@ -58,6 +58,18 @@ export const quoteRouter = router({
.input(GetQuoteInputDataSchema)
.output(GetQuoteOutputDataSchema)
.query(async ({ input }) => {
const { quote: quoteId } = input.values;
const apolloClient = initializeApollo();
const {
data: { quote },
} = await apolloClient.query({
query: CRMTypes.GetQuoteDataDocument,
variables: {
quoteId,
},
});
const processData = await Promise.all(
[
configurator,
@ -73,7 +85,7 @@ export const quoteRouter = router({
addProduct,
createKpProcess,
eltProcess,
].map(({ getKPData }) => getKPData(input))
].map(({ getKPData }) => getKPData({ ...input, quote }))
);
const values = processData.reduce((obj, data) => ({ ...obj, ...data.values }), defaultValues);

View File

@ -4,6 +4,7 @@ import { RiskSchema } from '@/config/schema/fingap';
import { KeysSchema, RowSchema } from '@/config/schema/insurance';
import PaymentsSchema from '@/config/schema/payments';
import ValuesSchema from '@/config/schema/values';
import type * as CRMTypes from '@/graphql/crm.types';
import { z } from 'zod';
const { quote, recalcWithRevision, lead, opportunity } = ValuesSchema.shape;
@ -21,7 +22,9 @@ export const GetQuoteInputDataSchema = z
})
.strict();
export type GetQuoteInputData = z.infer<typeof GetQuoteInputDataSchema>;
export type GetQuoteInputData = z.infer<typeof GetQuoteInputDataSchema> & {
quote: CRMTypes.GetQuoteDataQuery['quote'];
};
const FinGAPSchema = z.object({
keys: z.array(RiskSchema.shape.key),