add elt api types

This commit is contained in:
vchikalkin 2023-05-06 11:49:05 +03:00
parent b14af40b44
commit c3db0beaf2
11 changed files with 373 additions and 20 deletions

4
.env
View File

@ -9,4 +9,6 @@ URL_CRM_CREATEKP_DIRECT=
URL_CRM_DOWNLOADKP_BASE=
URL_CORE_FINGAP_DIRECT=
URL_CORE_CALCULATE_DIRECT=
URL_1C_TRANSTAX_DIRECT=
URL_1C_TRANSTAX_DIRECT=
URL_ELT_OSAGO_DIRECT=
URL_ELT_KASKO_DIRECT=

View File

@ -22,6 +22,10 @@ export const PolicyTable = observer(({ getter, ...props }) => {
selectedRowKeys: getSelectedRow ? [getSelectedRow.key] : [],
type: 'radio',
}}
expandable={{
expandedRowRender: (record) => record.message,
rowExpandable: (record) => record.message || record.children,
}}
{...props}
/>
);

18
apps/web/api/elt/query.ts Normal file
View File

@ -0,0 +1,18 @@
import type * as ELT from './types';
import getUrls from '@/config/urls';
import type { QueryFunctionContext } from '@tanstack/react-query';
import axios from 'axios';
const { URL_ELT_KASKO, URL_ELT_OSAGO } = getUrls();
export async function getEltOsago(payload: ELT.RequestEltOsago, { signal }: QueryFunctionContext) {
const { data } = await axios.post<ELT.ResponseEltOsago>(URL_ELT_OSAGO, payload, { signal });
return data;
}
export async function getEltKasko(payload: ELT.RequestEltKasko, { signal }: QueryFunctionContext) {
const { data } = await axios.post<ELT.ResponseEltKasko>(URL_ELT_KASKO, payload, { signal });
return data;
}

12
apps/web/api/elt/types.ts Normal file
View File

@ -0,0 +1,12 @@
import type {
RequestEltKaskoSchema,
RequestEltOsagoSchema,
ResultEltKaskoSchema,
ResultEltOsagoSchema,
} from '@/config/schema/elt';
import type { z } from 'zod';
export type RequestEltOsago = z.infer<typeof RequestEltOsagoSchema>;
export type RequestEltKasko = z.infer<typeof RequestEltKaskoSchema>;
export type ResponseEltOsago = z.infer<typeof ResultEltOsagoSchema>;
export type ResponseEltKasko = z.infer<typeof ResultEltKaskoSchema>;

View File

@ -1,9 +1,276 @@
import { z } from 'zod';
export const RequestEltKaskoSchema = z.object({
ELTParams: z.object({
Insurer: z.object({
SubjectType: z.number(),
SubjectTypeSpecified: z.boolean(),
}),
Lessee: z.object({
INN: z.string(),
SubjectType: z.number(),
SubjectTypeSpecified: z.boolean(),
}),
OfficialDealer: z.boolean(),
OfficialDealerSpecified: z.boolean(),
Owner: z.object({
SubjectType: z.number(),
SubjectTypeSpecified: z.boolean(),
}),
STOA: z.string(),
approvedDriving: z.number(),
approvedDrivingSpecified: z.boolean(),
bankId: z.string(),
cost: z.number(),
currency: z.string(),
drivers: z.array(
z.object({
age: z.number(),
experience: z.number(),
sex: z.string(),
sexSpecified: z.boolean(),
})
),
driversCount: z.number(),
duration: z.number(),
franchise: z.number(),
franchiseSpecified: z.boolean(),
isNew: z.boolean(),
modification: z.object({
KPPTypeId: z.number(),
country: z.number(),
countrySpecified: z.boolean(),
engineType: z.string(),
engineVolume: z.number(),
engineVolumeSpecified: z.boolean(),
power: z.number(),
powerSpecified: z.boolean(),
}),
notConfirmedDamages: z.number(),
notConfirmedDamagesSpecified: z.boolean(),
notConfirmedGlassesDamages: z.number(),
notConfirmedGlassesDamagesSpecified: z.boolean(),
outsideRoads: z.boolean(),
outsideRoadsSpecified: z.boolean(),
payType: z.string(),
risk: z.number(),
selfIgnition: z.boolean(),
selfIgnitionSpecified: z.boolean(),
ssType: z.string(),
usageStart: z.string(),
vehicle: z.object({
category: z.string(),
classification: z.string(),
maxAllowedMass: z.number(),
maxAllowedMassSpecified: z.boolean(),
mileage: z.number(),
mileageSpecified: z.boolean(),
seatingCapacity: z.number(),
seatingCapacitySpecified: z.boolean(),
vehicleUsage: z.number(),
vehicleUsageSpecified: z.boolean(),
}),
vehicleDateSpecified: z.boolean(),
vehicleYear: z.number(),
}),
companyIds: z.array(z.string()),
preparams: z.object({
brandId: z.string(),
kladr: z.string(),
modelId: z.string(),
specialMachinery: z.object({
industry: z.number(),
industrySpecified: z.boolean(),
mover: z.number(),
moverSpecified: z.boolean(),
type: z.number(),
typeSpecified: z.boolean(),
}),
}),
});
export const ResultEltKaskoSchema = z.record(
z.object({
calcInfo: z.null(),
comment: z.null(),
doSum: z.number(),
error: z.string(),
errorType: z.null(),
gapSum: z.number(),
goSum: z.number(),
insuranceCompanyFranchise: z.object({ id: z.string(), value: z.string() }),
insuranceCompanyGo: z.object({ id: z.string(), value: z.string() }),
isNeedInspection: z.string(),
kaskoSum: z.number(),
kbmOsago: z.null(),
message: z.string(),
nsSum: z.number(),
options: z.array(
z.union([
z.object({
id: z.string(),
name: z.string(),
values: z.array(z.object({ id: z.string(), name: z.string() })),
}),
z.object({
id: z.string(),
name: z.string(),
values: z.array(z.object({ id: z.string(), name: z.null() })),
}),
z.object({
id: z.string(),
name: z.string(),
values: z.array(z.object({ id: z.null(), name: z.null() })),
}),
])
),
paymentPeriods: z.array(
z.object({
date: z.string(),
doSum: z.number(),
doSumSpecified: z.boolean(),
duration: z.number(),
durationSpecified: z.boolean(),
franchiseSum: z.number(),
franchiseSumSpecified: z.boolean(),
gapSum: z.number(),
gapSumSpecified: z.boolean(),
goSum: z.number(),
goSumSpecified: z.boolean(),
id: z.null(),
kaskoSum: z.number(),
kaskoSumSpecified: z.boolean(),
name: z.null(),
nsSum: z.number(),
nsSumSpecified: z.boolean(),
num: z.number(),
numSpecified: z.boolean(),
premiumSum: z.number(),
premiumSumSpecified: z.boolean(),
rate: z.number(),
rateSpecified: z.boolean(),
})
),
policyNumber: z.null(),
premiumSum: z.number(),
product: z.string(),
productId: z.string(),
program: z.string(),
programCode: z.string(),
programId: z.string(),
requestId: z.string(),
skCalcId: z.string(),
totalFranchise: z.number(),
totalFranchiseSpecified: z.boolean(),
unicusGUID: z.string(),
})
);
export const RequestEltOsagoSchema = z.object({
ELTParams: z.object({
FullDriversInfo: z.array(z.object({ kbm: z.string() })),
carInfo: z.object({
tsType: z.object({ category: z.string(), subCategory: z.string() }),
useWithTrailer: z.boolean(),
useWithTrailerSpecified: z.boolean(),
vehicle: z.object({
maxAllowedMass: z.number(),
maxAllowedMassSpecified: z.boolean(),
seatingCapacity: z.number(),
seatingCapacitySpecified: z.boolean(),
}),
vehiclePower: z.number(),
vehicleYear: z.string(),
}),
contractBeginDate: z.string(),
contractOptionId: z.number(),
contractStatusId: z.number(),
driversCount: z.number(),
duration: z.number(),
insurer: z.object({
INN: z.string(),
SubjectType: z.number(),
SubjectTypeSpecified: z.boolean(),
}),
insurerType: z.number(),
lessee: z.object({
SubjectType: z.number(),
SubjectTypeSpecified: z.boolean(),
inn: z.string(),
}),
owner: z.object({
JuridicalName: z.string(),
email: z.string(),
factAddress: z.object({
city: z.string(),
cityKladr: z.string(),
country: z.string(),
flat: z.string(),
house: z.string(),
region: z.string(),
resident: z.number(),
street: z.string(),
}),
inn: z.string(),
kpp: z.string(),
ogrn: z.string(),
opf: z.number(),
opfSpecified: z.boolean(),
phone: z.string(),
registrationAddress: z.object({
city: z.string(),
cityKladr: z.string(),
country: z.string(),
flat: z.string(),
house: z.string(),
region: z.string(),
resident: z.number(),
street: z.string(),
}),
subjectType: z.number(),
subjectTypeSpecified: z.boolean(),
}),
ownerType: z.number(),
tsToRegistrationPlace: z.number(),
}),
companyIds: z.array(z.string()),
preparams: z.object({
brandId: z.string(),
kladr: z.string(),
modelId: z.string(),
}),
});
export const ResultEltOsagoSchema = z.record(
z.object({
calcInfo: z.array(
z.object({
itemName: z.string(),
value: z.number(),
valueSpecified: z.boolean(),
})
),
error: z.string(),
fullDriversInfo: z.array(z.unknown()),
kbm: z.object({ class: z.number(), value: z.number() }),
message: z.string(),
numCalc: z.number(),
premiumSum: z.number(),
prevoiusKBM: z.object({ class: z.number(), value: z.number() }),
rsaRequestId: z.string(),
skCalcId: z.string(),
tb: z.number(),
})
);
export const RowSchema = z.object({
isFetching: z.boolean(),
key: z.string(),
message: z.string().nullable(),
name: z.string(),
numCalc: z.number(),
requestId: z.string(),
skCalcId: z.string(),
sum: z.number(),
totalFranchise: z.number(),
});

View File

@ -9,6 +9,8 @@ const envSchema = z.object({
URL_CRM_CREATEKP_DIRECT: z.string(),
URL_CRM_DOWNLOADKP_BASE: z.string(),
URL_CRM_GRAPHQL_DIRECT: z.string(),
URL_ELT_KASKO_DIRECT: z.string(),
URL_ELT_OSAGO_DIRECT: z.string(),
URL_GET_USER_DIRECT: z.string(),
USE_DEV_COLORS: z.unknown().optional().transform(Boolean),
});

View File

@ -14,6 +14,8 @@ const serverRuntimeConfigSchema = envSchema.pick({
URL_CRM_CREATEKP_DIRECT: true,
URL_CRM_DOWNLOADKP_BASE: true,
URL_CRM_GRAPHQL_DIRECT: true,
URL_ELT_KASKO_DIRECT: true,
URL_ELT_OSAGO_DIRECT: true,
URL_GET_USER_DIRECT: true,
});

View File

@ -18,6 +18,8 @@ function getUrls() {
URL_CRM_CREATEKP_DIRECT,
URL_CRM_DOWNLOADKP_BASE,
PORT,
URL_ELT_KASKO_DIRECT,
URL_ELT_OSAGO_DIRECT,
} = serverRuntimeConfigSchema.parse(serverRuntimeConfig);
return {
@ -29,6 +31,8 @@ function getUrls() {
URL_CRM_CREATEKP: URL_CRM_CREATEKP_DIRECT,
URL_CRM_DOWNLOADKP_BASE,
URL_CRM_GRAPHQL: URL_CRM_GRAPHQL_DIRECT,
URL_ELT_KASKO: URL_ELT_KASKO_DIRECT,
URL_ELT_OSAGO: URL_ELT_OSAGO_DIRECT,
URL_GET_USER: URL_GET_USER_DIRECT,
};
}
@ -44,6 +48,8 @@ function getUrls() {
URL_CORE_FINGAP: withBasePath(urls.URL_CORE_FINGAP_PROXY),
URL_CRM_CREATEKP: withBasePath(urls.URL_CRM_CREATEKP_PROXY),
URL_CRM_GRAPHQL: withBasePath(urls.URL_CRM_GRAPHQL_PROXY),
URL_ELT_KASKO: urls.URL_ELT_KASKO,
URL_ELT_OSAGO: urls.URL_ELT_OSAGO,
URL_GET_USER: withBasePath(urls.URL_GET_USER_PROXY),
};
}

View File

@ -4,5 +4,7 @@ module.exports = {
URL_CORE_FINGAP_PROXY: '/api/core/fingap',
URL_CRM_CREATEKP_PROXY: '/api/crm/create-kp',
URL_CRM_GRAPHQL_PROXY: '/api/graphql/crm',
URL_ELT_KASKO: '/api/elt/kasko',
URL_ELT_OSAGO: '/api/elt/osago',
URL_GET_USER_PROXY: '/api/auth/user',
};

View File

@ -1,5 +1,6 @@
import getUrls from '@/config/urls';
import { rest } from 'msw';
const _ = require('radash');
const users = {
@ -12,37 +13,66 @@ const users = {
domain: 'EVOLEASING',
domainName: 'EVOLEASING\\akalinina',
},
vchikalkin: {
username: 'vchikalkin',
displayName: 'Влад Чикалкин',
mail: 'vchikalkin@evoleasing.ru',
domain: 'EVOLEASING',
department: 'IT',
position: 'Старший разработчик',
domainName: 'EVOLEASING\\vchikalkin',
},
// vchikalkin: {
// username: 'vchikalkin',
// displayName: 'Влад Чикалкин',
// mail: 'vchikalkin@evoleasing.ru',
// domain: 'EVOLEASING',
// department: 'IT',
// position: 'Старший разработчик',
// domainName: 'EVOLEASING\\vchikalkin',
// },
};
const { URL_GET_USER, URL_CORE_FINGAP, URL_1C_TRANSTAX } = getUrls();
const { URL_GET_USER, URL_CORE_FINGAP, URL_1C_TRANSTAX, URL_ELT_OSAGO, URL_ELT_KASKO } = getUrls();
export const handlers = [
rest.get(URL_GET_USER, (req, res, ctx) => {
return res(ctx.json(users.akalinina));
}),
rest.post(URL_CORE_FINGAP, (req, res, ctx) => {
return res(
rest.get(URL_GET_USER, (req, res, ctx) => res(ctx.json(users.akalinina))),
rest.post(URL_CORE_FINGAP, (req, res, ctx) => res(
ctx.json({
sum: _.random(100000, 200000),
premium: _.random(1000, 10000),
})
);
}),
rest.post(URL_1C_TRANSTAX, (req, res, ctx) => {
return res(
)),
rest.post(URL_1C_TRANSTAX, (req, res, ctx) => res(
ctx.json({
error: null,
tax: _.random(100000, 200000),
})
)),
rest.post(URL_ELT_OSAGO, async (req, res, ctx) => {
const companyId = (await req.json()).companyIds[0];
return res(
ctx.json({
[companyId]: {
numCalc: _.random(1000000, 3000000),
skCalcId: _.random(50000000, 60000000).toString(),
premiumSum: _.random(10000, 20000),
message: 'OSAGO Message',
},
})
);
}),
rest.post(URL_ELT_KASKO, async (req, res, ctx) => {
const companyId = (await req.json()).companyIds[0];
return res(
ctx.json({
[companyId]: {
requestId: _.random(3000000, 4000000).toString(),
skCalcId: _.random(50000000, 60000000).toString(),
message: 'KASKO Message',
premiumSum: _.random(100000, 200000),
kaskoSum: _.random(100000, 200000),
paymentPeriods: [
{
num: 1,
kaskoSum: _.random(100000, 200000),
},
],
totalFranchise: _.random(20000, 40000),
},
})
);
}),

View File

@ -38,7 +38,11 @@ export default function helper({ apolloClient, store }: ProcessContext) {
.map((x) => ({
isFetching: false,
key: x?.value,
message: null,
name: x?.label,
numCalc: 0,
requestId: '',
skCalcId: '',
sum: 0,
totalFranchise: 0,
})) || []) as Row[],
@ -47,7 +51,11 @@ export default function helper({ apolloClient, store }: ProcessContext) {
.map((x) => ({
isFetching: false,
key: x?.value,
message: null,
name: x?.label,
numCalc: 0,
requestId: '',
skCalcId: '',
sum: 0,
totalFranchise: 0,
})) || []) as Row[],