72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
/* eslint-disable canonical/sort-keys */
|
|
import { t } from '../server';
|
|
import defaultValues from '@/config/default-values';
|
|
import * as insuranceTable from '@/config/tables/insurance-table';
|
|
import * as addProduct from '@/process/add-product';
|
|
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';
|
|
import * as price from '@/process/price';
|
|
import * as subsidy from '@/process/subsidy';
|
|
import * as supplierAgent from '@/process/supplier-agent';
|
|
|
|
const { GetQuoteInputDataSchema, GetQuoteOutputDataSchema } = loadKP;
|
|
const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable;
|
|
|
|
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(GetQuoteInputDataSchema)
|
|
.output(GetQuoteOutputDataSchema)
|
|
.query(async ({ input }) => {
|
|
const processData = await Promise.all(
|
|
[
|
|
configurator,
|
|
supplierAgent,
|
|
paymentsProcess,
|
|
price,
|
|
bonuses,
|
|
leasingObject,
|
|
fingapProcess,
|
|
gibdd,
|
|
subsidy,
|
|
insuranceProcess,
|
|
addProduct,
|
|
].map(({ getKPData }) => getKPData(input))
|
|
);
|
|
|
|
const values = processData.reduce(
|
|
(obj, data) => Object.assign(obj, data.values),
|
|
defaultValues
|
|
);
|
|
const payments = processData.find((x) => x.payments)?.payments ?? defaultPayments;
|
|
const insurance = processData.find((x) => x.insurance)?.insurance ?? defaultInsurance;
|
|
const fingap = processData.find((x) => x.fingap)?.fingap ?? defaultFingap;
|
|
|
|
return {
|
|
values,
|
|
payments,
|
|
insurance,
|
|
fingap,
|
|
};
|
|
}),
|
|
});
|
|
|
|
export default quoteRouter;
|