trpc/create-kp: add downloadKp url to result

This commit is contained in:
vchikalkin 2023-04-04 13:27:07 +03:00
parent 79179c10f3
commit 06e7687fc1
11 changed files with 22 additions and 1 deletions

1
.env
View File

@ -6,6 +6,7 @@ BASE_PATH=
URL_GET_USER_DIRECT=
URL_CRM_GRAPHQL_DIRECT=
URL_CRM_CREATEKP_DIRECT=
URL_CRM_DOWNLOADKP_BASE=
URL_CORE_FINGAP_DIRECT=
URL_CORE_CALCULATE_DIRECT=
URL_1C_TRANSTAX_DIRECT=

View File

@ -139,7 +139,7 @@ const elementsToValues = wrapElementsMap({
selectLeasingWithoutKasko: 'leasingWithoutKasko',
/** Link Elements */
linkDownloadKp: 'kpUrl',
linkDownloadKp: 'downloadKp',
linkLeadUrl: 'leadUrl',
linkOpportunityUrl: 'opportunityUrl',
linkQuoteUrl: 'quoteUrl',

View File

@ -29,6 +29,11 @@ export type RequestCreateKP = z.infer<typeof RequestCreateKPSchema>;
export const ResponseCreateKPSchema = z.union([
z.object({
evo_quotename: z.string(),
link: z.string(),
name: z.string(),
offerprintform: z.string(),
offerprintformapi: z.string(),
quoteid: z.string(),
success: z.literal(true),
}),
z.object({

View File

@ -35,6 +35,7 @@ const defaultValues: CalculationValues = {
depreciationGroup: '-',
disableChecks: false,
discountRub: 0,
downloadKp: null,
engineHours: 0,
engineType: 100_000_000,
engineVolume: 0,

View File

@ -7,6 +7,7 @@ const envSchema = z.object({
URL_CORE_CALCULATE_DIRECT: z.string(),
URL_CORE_FINGAP_DIRECT: z.string(),
URL_CRM_CREATEKP_DIRECT: z.string(),
URL_CRM_DOWNLOADKP_BASE: z.string(),
URL_CRM_GRAPHQL_DIRECT: z.string(),
URL_GET_USER_DIRECT: z.string(),
USE_DEV_COLORS: z.unknown().optional().transform(Boolean),

View File

@ -12,6 +12,7 @@ const serverRuntimeConfigSchema = envSchema.pick({
URL_CORE_CALCULATE_DIRECT: true,
URL_CORE_FINGAP_DIRECT: true,
URL_CRM_CREATEKP_DIRECT: true,
URL_CRM_DOWNLOADKP_BASE: true,
URL_CRM_GRAPHQL_DIRECT: true,
URL_GET_USER_DIRECT: true,
});

View File

@ -128,6 +128,7 @@ const ValuesSchema = z.object({
/**
* Link Values
*/
downloadKp: z.string().nullable(),
kpUrl: z.string().nullable(),
leadUrl: z.string().nullable(),
opportunityUrl: z.string().nullable(),

View File

@ -16,6 +16,7 @@ function getUrls() {
URL_1C_TRANSTAX_DIRECT,
URL_CORE_CALCULATE_DIRECT,
URL_CRM_CREATEKP_DIRECT,
URL_CRM_DOWNLOADKP_BASE,
PORT,
} = serverRuntimeConfigSchema.parse(serverRuntimeConfig);
@ -26,6 +27,7 @@ function getUrls() {
URL_CORE_CALCULATE: URL_CORE_CALCULATE_DIRECT,
URL_CORE_FINGAP: URL_CORE_FINGAP_DIRECT,
URL_CRM_CREATEKP: URL_CRM_CREATEKP_DIRECT,
URL_CRM_DOWNLOADKP_BASE,
URL_CRM_GRAPHQL: URL_CRM_GRAPHQL_DIRECT,
URL_GET_USER: URL_GET_USER_DIRECT,
};

View File

@ -87,6 +87,7 @@ export function transformCalculateResults({
const values: OutputData['values'] = {
IRR_Perc: columns?.cashflowMsfoColumn?.nominal * 100,
downloadKp: null,
lastPaymentRub: last(columns?.sumWithVatColumn?.values) || 0,
totalPayments: columns?.sumWithVatColumn?.values[0] - inputValues.subsidySum,
};

View File

@ -22,6 +22,7 @@ export const OutputDataSchema = z.object({
resultValues: ResultValuesSchema,
values: ValuesSchema.pick({
IRR_Perc: true,
downloadKp: true,
lastPaymentRub: true,
totalPayments: true,
}),

View File

@ -17,6 +17,7 @@ import type { User } from '@/api/user/types';
import initializeApollo from '@/apollo/client';
import defaultValues from '@/config/default-values';
import * as insuranceTable from '@/config/tables/insurance-table';
import getUrls from '@/config/urls';
import * as CRMTypes from '@/graphql/crm.types';
import * as addProduct from '@/process/add-product';
import * as bonuses from '@/process/bonuses';
@ -46,6 +47,8 @@ const defaultInsurance = {
const defaultFingap = { keys: [] };
const defaultPayments = { values: [] };
const { URL_CRM_DOWNLOADKP_BASE } = getUrls();
export const quoteRouter = router({
getQuote: publicProcedure
.input(GetQuoteInputDataSchema)
@ -158,6 +161,10 @@ export const quoteRouter = router({
responseCalculate: calculateResult,
});
if (URL_CRM_DOWNLOADKP_BASE) {
result.values.downloadKp = URL_CRM_DOWNLOADKP_BASE?.concat(createKPResult.evo_quotename);
}
return {
data: result,
success: true,