Compare commits
7 Commits
dev
...
refactor/e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d9c35b953 | ||
|
|
4dd4038091 | ||
|
|
3aea4c439f | ||
|
|
240b92f84d | ||
|
|
0170d64700 | ||
|
|
2a8e3fb443 | ||
|
|
af34a55c17 |
@ -57,7 +57,6 @@ export const Kasko = observer(() => {
|
|||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const companyRes = res?.[row.id];
|
|
||||||
const {
|
const {
|
||||||
kaskoSum = 0,
|
kaskoSum = 0,
|
||||||
message,
|
message,
|
||||||
@ -65,8 +64,8 @@ export const Kasko = observer(() => {
|
|||||||
totalFranchise = 0,
|
totalFranchise = 0,
|
||||||
requestId,
|
requestId,
|
||||||
paymentPeriods,
|
paymentPeriods,
|
||||||
} = companyRes;
|
} = res;
|
||||||
let { error } = companyRes;
|
let { error } = res;
|
||||||
|
|
||||||
if (totalFranchise > MAX_FRANCHISE) {
|
if (totalFranchise > MAX_FRANCHISE) {
|
||||||
error ||= `Франшиза по страховке превышает максимально допустимое значение: ${Intl.NumberFormat(
|
error ||= `Франшиза по страховке превышает максимально допустимое значение: ${Intl.NumberFormat(
|
||||||
@ -111,10 +110,11 @@ export const Kasko = observer(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
const _err = error as Error;
|
||||||
$tables.elt.kasko.setRow({
|
$tables.elt.kasko.setRow({
|
||||||
...initialData,
|
...initialData,
|
||||||
key,
|
key,
|
||||||
message: error,
|
message: _err.message || String(error),
|
||||||
status: 'error',
|
status: 'error',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -51,9 +51,8 @@ export const Osago = observer(() => {
|
|||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const companyRes = res?.[row.id];
|
const { numCalc, premiumSum = 0, message, skCalcId } = res;
|
||||||
const { numCalc, premiumSum = 0, message, skCalcId } = companyRes;
|
let { error } = res;
|
||||||
let { error } = companyRes;
|
|
||||||
if (premiumSum > MAX_INSURANCE) {
|
if (premiumSum > MAX_INSURANCE) {
|
||||||
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости ОСАГО: ${Intl.NumberFormat(
|
error ||= `Сумма по страховке превышает максимально допустимое значение по стоимости ОСАГО: ${Intl.NumberFormat(
|
||||||
'ru',
|
'ru',
|
||||||
@ -83,10 +82,11 @@ export const Osago = observer(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
const _err = error as Error;
|
||||||
$tables.elt.osago.setRow({
|
$tables.elt.osago.setRow({
|
||||||
...initialData,
|
...initialData,
|
||||||
key,
|
key,
|
||||||
message: error,
|
message: _err.message || String(error),
|
||||||
status: 'error',
|
status: 'error',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -231,7 +231,8 @@ export async function makeEltOsagoRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ELTParams: {
|
companyId: row.id,
|
||||||
|
params: {
|
||||||
FullDriversInfo: [
|
FullDriversInfo: [
|
||||||
{
|
{
|
||||||
kbm: '3',
|
kbm: '3',
|
||||||
@ -272,7 +273,6 @@ export async function makeEltOsagoRequest(
|
|||||||
ownerType: 1,
|
ownerType: 1,
|
||||||
tsToRegistrationPlace: 0,
|
tsToRegistrationPlace: 0,
|
||||||
},
|
},
|
||||||
companyIds: [row.id],
|
|
||||||
preparams: {
|
preparams: {
|
||||||
brandId,
|
brandId,
|
||||||
kladr,
|
kladr,
|
||||||
@ -611,7 +611,8 @@ export async function makeEltKaskoRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ELTParams: {
|
companyId: row.id,
|
||||||
|
params: {
|
||||||
Insurer: {
|
Insurer: {
|
||||||
SubjectType: 1,
|
SubjectType: 1,
|
||||||
SubjectTypeSpecified: true,
|
SubjectTypeSpecified: true,
|
||||||
@ -697,7 +698,6 @@ export async function makeEltKaskoRequest(
|
|||||||
// },
|
// },
|
||||||
// ],
|
// ],
|
||||||
},
|
},
|
||||||
companyIds: [row.id],
|
|
||||||
preparams: {
|
preparams: {
|
||||||
brandId,
|
brandId,
|
||||||
kladr,
|
kladr,
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const RequestEltKaskoSchema = z.object({
|
export const RequestEltKaskoSchema = z.object({
|
||||||
ELTParams: z.object({
|
companyId: z.string(),
|
||||||
|
params: z.object({
|
||||||
Insurer: z.object({
|
Insurer: z.object({
|
||||||
SubjectType: z.number(),
|
SubjectType: z.number(),
|
||||||
SubjectTypeSpecified: z.boolean(),
|
SubjectTypeSpecified: z.boolean(),
|
||||||
@ -82,7 +83,6 @@ export const RequestEltKaskoSchema = z.object({
|
|||||||
vehicleDateSpecified: z.boolean(),
|
vehicleDateSpecified: z.boolean(),
|
||||||
vehicleYear: z.number(),
|
vehicleYear: z.number(),
|
||||||
}),
|
}),
|
||||||
companyIds: z.array(z.string()),
|
|
||||||
preparams: z.object({
|
preparams: z.object({
|
||||||
brandId: z.string(),
|
brandId: z.string(),
|
||||||
kladr: z.string(),
|
kladr: z.string(),
|
||||||
@ -98,85 +98,84 @@ export const RequestEltKaskoSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ResultEltKaskoSchema = z.record(
|
export const ResultEltKaskoSchema = z.object({
|
||||||
z.object({
|
calcInfo: z.null(),
|
||||||
calcInfo: z.null(),
|
comment: z.null(),
|
||||||
comment: z.null(),
|
doSum: z.number(),
|
||||||
doSum: z.number(),
|
error: z.string(),
|
||||||
error: z.string(),
|
errorType: z.null(),
|
||||||
errorType: z.null(),
|
gapSum: z.number(),
|
||||||
gapSum: z.number(),
|
goSum: z.number(),
|
||||||
goSum: z.number(),
|
insuranceCompanyFranchise: z.object({ id: z.string(), value: z.string() }),
|
||||||
insuranceCompanyFranchise: z.object({ id: z.string(), value: z.string() }),
|
insuranceCompanyGo: z.object({ id: z.string(), value: z.string() }),
|
||||||
insuranceCompanyGo: z.object({ id: z.string(), value: z.string() }),
|
isNeedInspection: z.string(),
|
||||||
isNeedInspection: z.string(),
|
kaskoSum: z.number(),
|
||||||
kaskoSum: z.number(),
|
kbmOsago: z.null(),
|
||||||
kbmOsago: z.null(),
|
message: z.string(),
|
||||||
message: z.string(),
|
nsSum: z.number(),
|
||||||
nsSum: z.number(),
|
options: z.array(
|
||||||
options: z.array(
|
z.union([
|
||||||
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({
|
z.object({
|
||||||
date: z.string(),
|
id: z.string(),
|
||||||
doSum: z.number(),
|
name: z.string(),
|
||||||
doSumSpecified: z.boolean(),
|
values: z.array(z.object({ id: z.string(), name: z.string() })),
|
||||||
duration: z.number(),
|
}),
|
||||||
durationSpecified: z.boolean(),
|
z.object({
|
||||||
franchiseSum: z.number(),
|
id: z.string(),
|
||||||
franchiseSumSpecified: z.boolean(),
|
name: z.string(),
|
||||||
gapSum: z.number(),
|
values: z.array(z.object({ id: z.string(), name: z.null() })),
|
||||||
gapSumSpecified: z.boolean(),
|
}),
|
||||||
goSum: z.number(),
|
z.object({
|
||||||
goSumSpecified: z.boolean(),
|
id: z.string(),
|
||||||
id: z.null(),
|
name: z.string(),
|
||||||
kaskoSum: z.number(),
|
values: z.array(z.object({ id: z.null(), name: z.null() })),
|
||||||
kaskoSumSpecified: z.boolean(),
|
}),
|
||||||
name: z.null(),
|
])
|
||||||
nsSum: z.number(),
|
),
|
||||||
nsSumSpecified: z.boolean(),
|
paymentPeriods: z.array(
|
||||||
num: z.number(),
|
z.object({
|
||||||
numSpecified: z.boolean(),
|
date: z.string(),
|
||||||
premiumSum: z.number(),
|
doSum: z.number(),
|
||||||
premiumSumSpecified: z.boolean(),
|
doSumSpecified: z.boolean(),
|
||||||
rate: z.number(),
|
duration: z.number(),
|
||||||
rateSpecified: z.boolean(),
|
durationSpecified: z.boolean(),
|
||||||
})
|
franchiseSum: z.number(),
|
||||||
),
|
franchiseSumSpecified: z.boolean(),
|
||||||
policyNumber: z.null(),
|
gapSum: z.number(),
|
||||||
premiumSum: z.number(),
|
gapSumSpecified: z.boolean(),
|
||||||
product: z.string(),
|
goSum: z.number(),
|
||||||
productId: z.string(),
|
goSumSpecified: z.boolean(),
|
||||||
program: z.string(),
|
id: z.null(),
|
||||||
programCode: z.string(),
|
kaskoSum: z.number(),
|
||||||
programId: z.string(),
|
kaskoSumSpecified: z.boolean(),
|
||||||
requestId: z.string(),
|
name: z.null(),
|
||||||
skCalcId: z.string(),
|
nsSum: z.number(),
|
||||||
totalFranchise: z.number(),
|
nsSumSpecified: z.boolean(),
|
||||||
totalFranchiseSpecified: z.boolean(),
|
num: z.number(),
|
||||||
unicusGUID: z.string(),
|
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({
|
export const RequestEltOsagoSchema = z.object({
|
||||||
ELTParams: z.object({
|
companyId: z.string(),
|
||||||
|
params: z.object({
|
||||||
FullDriversInfo: z.array(z.object({ kbm: z.string() })),
|
FullDriversInfo: z.array(z.object({ kbm: z.string() })),
|
||||||
carInfo: z.object({
|
carInfo: z.object({
|
||||||
mark: z.string(),
|
mark: z.string(),
|
||||||
@ -244,7 +243,6 @@ export const RequestEltOsagoSchema = z.object({
|
|||||||
ownerType: z.number(),
|
ownerType: z.number(),
|
||||||
tsToRegistrationPlace: z.number(),
|
tsToRegistrationPlace: z.number(),
|
||||||
}),
|
}),
|
||||||
companyIds: z.array(z.string()),
|
|
||||||
preparams: z.object({
|
preparams: z.object({
|
||||||
brandId: z.string(),
|
brandId: z.string(),
|
||||||
kladr: z.string(),
|
kladr: z.string(),
|
||||||
@ -252,27 +250,25 @@ export const RequestEltOsagoSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ResultEltOsagoSchema = z.record(
|
export const ResultEltOsagoSchema = z.object({
|
||||||
z.object({
|
calcInfo: z.array(
|
||||||
calcInfo: z.array(
|
z.object({
|
||||||
z.object({
|
itemName: z.string(),
|
||||||
itemName: z.string(),
|
value: z.number(),
|
||||||
value: z.number(),
|
valueSpecified: z.boolean(),
|
||||||
valueSpecified: z.boolean(),
|
})
|
||||||
})
|
),
|
||||||
),
|
error: z.string(),
|
||||||
error: z.string(),
|
fullDriversInfo: z.array(z.unknown()),
|
||||||
fullDriversInfo: z.array(z.unknown()),
|
kbm: z.object({ class: z.number(), value: z.number() }),
|
||||||
kbm: z.object({ class: z.number(), value: z.number() }),
|
message: z.string(),
|
||||||
message: z.string(),
|
numCalc: z.number(),
|
||||||
numCalc: z.number(),
|
premiumSum: z.number(),
|
||||||
premiumSum: z.number(),
|
prevoiusKBM: z.object({ class: z.number(), value: z.number() }),
|
||||||
prevoiusKBM: z.object({ class: z.number(), value: z.number() }),
|
rsaRequestId: z.string(),
|
||||||
rsaRequestId: z.string(),
|
skCalcId: z.string(),
|
||||||
skCalcId: z.string(),
|
tb: z.number(),
|
||||||
tb: z.number(),
|
});
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const RowSchema = z.object({
|
export const RowSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
|
|||||||
@ -28,53 +28,46 @@ const { URL_GET_USER, URL_CORE_FINGAP, URL_1C_TRANSTAX, URL_ELT_OSAGO, URL_ELT_K
|
|||||||
|
|
||||||
export const handlers = [
|
export const handlers = [
|
||||||
rest.get(URL_GET_USER, (req, res, ctx) => res(ctx.json(users.akalinina))),
|
rest.get(URL_GET_USER, (req, res, ctx) => res(ctx.json(users.akalinina))),
|
||||||
rest.post(URL_CORE_FINGAP, (req, res, ctx) => res(
|
rest.post(URL_CORE_FINGAP, (req, res, ctx) =>
|
||||||
|
res(
|
||||||
ctx.json({
|
ctx.json({
|
||||||
sum: _.random(100000, 200000),
|
sum: _.random(100000, 200000),
|
||||||
premium: _.random(1000, 10000),
|
premium: _.random(1000, 10000),
|
||||||
})
|
})
|
||||||
)),
|
)
|
||||||
rest.post(URL_1C_TRANSTAX, (req, res, ctx) => res(
|
),
|
||||||
|
rest.post(URL_1C_TRANSTAX, (req, res, ctx) =>
|
||||||
|
res(
|
||||||
ctx.json({
|
ctx.json({
|
||||||
error: null,
|
error: null,
|
||||||
tax: _.random(100000, 200000),
|
tax: _.random(100000, 200000),
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
),
|
||||||
|
rest.post(URL_ELT_OSAGO, async (req, res, ctx) => res(
|
||||||
|
ctx.json({
|
||||||
|
numCalc: _.random(1000000, 3000000),
|
||||||
|
skCalcId: _.random(50000000, 60000000).toString(),
|
||||||
|
premiumSum: _.random(10000, 20000),
|
||||||
|
message: 'OSAGO Message',
|
||||||
|
})
|
||||||
)),
|
)),
|
||||||
rest.post(URL_ELT_OSAGO, async (req, res, ctx) => {
|
rest.post(URL_ELT_KASKO, async (req, res, ctx) => res(
|
||||||
const companyId = (await req.json()).companyIds[0];
|
|
||||||
|
|
||||||
return res(
|
|
||||||
ctx.json({
|
ctx.json({
|
||||||
[companyId]: {
|
requestId: _.random(3000000, 4000000).toString(),
|
||||||
numCalc: _.random(1000000, 3000000),
|
skCalcId: _.random(50000000, 60000000).toString(),
|
||||||
skCalcId: _.random(50000000, 60000000).toString(),
|
message: 'KASKO Message',
|
||||||
premiumSum: _.random(10000, 20000),
|
premiumSum: _.random(100000, 200000),
|
||||||
message: 'OSAGO Message',
|
kaskoSum: _.random(100000, 200000),
|
||||||
},
|
paymentPeriods: [
|
||||||
|
{
|
||||||
|
num: 1,
|
||||||
|
kaskoSum: _.random(100000, 200000),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
totalFranchise: _.random(20000, 40000),
|
||||||
})
|
})
|
||||||
);
|
)),
|
||||||
}),
|
|
||||||
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),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
|
|
||||||
// rest.post(URL_CRM_GRAPHQL, (req, res, ctx) => {
|
// rest.post(URL_CRM_GRAPHQL, (req, res, ctx) => {
|
||||||
// return res(ctx.status(503));
|
// return res(ctx.status(503));
|
||||||
|
|||||||
@ -23,16 +23,17 @@ export default trpcNext.createNextApiHandler({
|
|||||||
onError(opts) {
|
onError(opts) {
|
||||||
const { error } = opts;
|
const { error } = opts;
|
||||||
// send to bug reporting
|
// send to bug reporting
|
||||||
withScope((scope) => {
|
if (!['BAD_REQUEST', 'UNAUTHORIZED', 'FORBIDDEN'].includes(error.code))
|
||||||
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
withScope((scope) => {
|
||||||
if (key !== 'req') {
|
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
||||||
let extra = opts[key];
|
if (key !== 'req') {
|
||||||
if (key === 'input') extra = JSON.stringify(extra);
|
let extra = opts[key];
|
||||||
scope.setExtra(key, extra);
|
if (key === 'input') extra = JSON.stringify(extra);
|
||||||
}
|
scope.setExtra(key, extra);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
captureException(error);
|
||||||
});
|
});
|
||||||
captureException(error);
|
|
||||||
});
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('Something went wrong', error);
|
console.error('Something went wrong', error);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -34,24 +34,15 @@ export async function action({ store, trpcClient }: ProcessContext) {
|
|||||||
values,
|
values,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.success === false) {
|
$results.setPayments(res.data.resultPayments);
|
||||||
notification.error({
|
$results.setValues(res.data.resultValues);
|
||||||
description: res.error,
|
$calculation.$values.setValues(res.data.values);
|
||||||
key,
|
|
||||||
message: errorMessage,
|
|
||||||
placement: 'bottomRight',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$results.setPayments(res.data.resultPayments);
|
|
||||||
$results.setValues(res.data.resultValues);
|
|
||||||
$calculation.$values.setValues(res.data.values);
|
|
||||||
|
|
||||||
notification.success({
|
notification.success({
|
||||||
key,
|
key,
|
||||||
message: successMessage,
|
message: successMessage,
|
||||||
placement: 'bottomRight',
|
placement: 'bottomRight',
|
||||||
});
|
});
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error_) => {
|
.catch((error_) => {
|
||||||
const error = error_ as Error;
|
const error = error_ as Error;
|
||||||
|
|||||||
@ -42,42 +42,33 @@ export function action({ store, trpcClient, apolloClient }: ProcessContext) {
|
|||||||
values,
|
values,
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (res.success === false) {
|
$results.setPayments(res.data.resultPayments);
|
||||||
notification.error({
|
$results.setValues(res.data.resultValues);
|
||||||
description: res.error,
|
$calculation.$values.setValues({ ...res.data.values, recalcWithRevision: false });
|
||||||
key,
|
|
||||||
message: errorMessage,
|
|
||||||
placement: 'bottomRight',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$results.setPayments(res.data.resultPayments);
|
|
||||||
$results.setValues(res.data.resultValues);
|
|
||||||
$calculation.$values.setValues({ ...res.data.values, recalcWithRevision: false });
|
|
||||||
|
|
||||||
notification.success({
|
notification.success({
|
||||||
key,
|
key,
|
||||||
message: successMessage,
|
message: successMessage,
|
||||||
placement: 'bottomRight',
|
placement: 'bottomRight',
|
||||||
|
});
|
||||||
|
|
||||||
|
const leadid = $calculation.element('selectLead').getValue();
|
||||||
|
|
||||||
|
if (leadid) {
|
||||||
|
const {
|
||||||
|
data: { quotes },
|
||||||
|
} = await apolloClient.query({
|
||||||
|
fetchPolicy: 'network-only',
|
||||||
|
query: CRMTypes.GetQuotesDocument,
|
||||||
|
variables: {
|
||||||
|
leadid,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const leadid = $calculation.element('selectLead').getValue();
|
$calculation
|
||||||
|
.element('selectQuote')
|
||||||
if (leadid) {
|
.setOptions(normalizeOptions(quotes))
|
||||||
const {
|
.setValue(values.quote);
|
||||||
data: { quotes },
|
|
||||||
} = await apolloClient.query({
|
|
||||||
fetchPolicy: 'network-only',
|
|
||||||
query: CRMTypes.GetQuotesDocument,
|
|
||||||
variables: {
|
|
||||||
leadid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
$calculation
|
|
||||||
.element('selectQuote')
|
|
||||||
.setOptions(normalizeOptions(quotes))
|
|
||||||
.setValue(values.quote);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error_) => {
|
.catch((error_) => {
|
||||||
|
|||||||
@ -2,13 +2,12 @@
|
|||||||
import eltHelper from '../elt/lib/helper';
|
import eltHelper from '../elt/lib/helper';
|
||||||
import { message } from '@/Components/Common/Notification';
|
import { message } from '@/Components/Common/Notification';
|
||||||
import type { ProcessContext } from '@/process/types';
|
import type { ProcessContext } from '@/process/types';
|
||||||
import { captureException, withScope } from '@sentry/nextjs';
|
|
||||||
import { reaction } from 'mobx';
|
import { reaction } from 'mobx';
|
||||||
import { omit } from 'radash';
|
import { omit } from 'radash';
|
||||||
|
|
||||||
const key = 'KP_LOADING_INFO';
|
const key = 'KP_LOADING_INFO';
|
||||||
|
|
||||||
export function common({ store, trpcClient, apolloClient, user }: ProcessContext) {
|
export function common({ store, trpcClient, apolloClient }: ProcessContext) {
|
||||||
const { $calculation, $process, $tables } = store;
|
const { $calculation, $process, $tables } = store;
|
||||||
|
|
||||||
const { init: initElt } = eltHelper({ apolloClient, store });
|
const { init: initElt } = eltHelper({ apolloClient, store });
|
||||||
@ -86,18 +85,12 @@ export function common({ store, trpcClient, apolloClient, user }: ProcessContext
|
|||||||
key,
|
key,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error_) => {
|
.catch(() => {
|
||||||
message.error({
|
message.error({
|
||||||
content: `Ошибка во время загрузки КП ${quote.label}`,
|
content: `Ошибка во время загрузки КП ${quote.label}`,
|
||||||
key,
|
key,
|
||||||
});
|
});
|
||||||
$calculation.element('selectQuote').resetValue();
|
$calculation.element('selectQuote').resetValue();
|
||||||
|
|
||||||
withScope((scope) => {
|
|
||||||
scope.setExtra('quote', quote);
|
|
||||||
scope.setExtra('user', user);
|
|
||||||
captureException(error_);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
$process.delete('LoadKP');
|
$process.delete('LoadKP');
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import { calculate } from '@/api/core/query';
|
|||||||
import type { User } from '@/api/user/types';
|
import type { User } from '@/api/user/types';
|
||||||
import initializeApollo from '@/apollo/client';
|
import initializeApollo from '@/apollo/client';
|
||||||
import { protectedProcedure } from '@/server/procedure';
|
import { protectedProcedure } from '@/server/procedure';
|
||||||
|
import { HttpError } from '@/utils/error';
|
||||||
|
import { createTRPCError } from '@/utils/trpc';
|
||||||
import { QueryClient } from '@tanstack/react-query';
|
import { QueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
export const calculateRouter = router({
|
export const calculateRouter = router({
|
||||||
@ -17,55 +19,56 @@ export const calculateRouter = router({
|
|||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
if (!ctx.unlimited) {
|
try {
|
||||||
const validationResult = await validate({
|
if (!ctx.unlimited) {
|
||||||
|
const validationResult = await validate({
|
||||||
|
context: {
|
||||||
|
apolloClient,
|
||||||
|
queryClient,
|
||||||
|
user: ctx.user,
|
||||||
|
},
|
||||||
|
input,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validationResult.success === false) {
|
||||||
|
throw new HttpError(validationResult.message, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let user: Pick<User, 'domainName'> = { domainName: ctx.user.domainName };
|
||||||
|
if (ctx.unlimited && input.values.user) {
|
||||||
|
user = { domainName: input.values.user };
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestData = await createRequestData({
|
||||||
context: {
|
context: {
|
||||||
apolloClient,
|
apolloClient,
|
||||||
queryClient,
|
queryClient,
|
||||||
user: ctx.user,
|
...ctx,
|
||||||
|
user,
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (validationResult.success === false) {
|
const calculateResult = await calculate(requestData);
|
||||||
return {
|
|
||||||
error: validationResult.error,
|
const result = transformCalculateResults({
|
||||||
success: false,
|
calculateInput: input,
|
||||||
};
|
requestCalculate: requestData,
|
||||||
|
responseCalculate: calculateResult,
|
||||||
|
});
|
||||||
|
|
||||||
|
// TEMP
|
||||||
|
if (ctx.unlimited) {
|
||||||
|
result.__calculateResult = calculateResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: result,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw createTRPCError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user: Pick<User, 'domainName'> = { domainName: ctx.user.domainName };
|
|
||||||
if (ctx.unlimited && input.values.user) {
|
|
||||||
user = { domainName: input.values.user };
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = await createRequestData({
|
|
||||||
context: {
|
|
||||||
apolloClient,
|
|
||||||
queryClient,
|
|
||||||
...ctx,
|
|
||||||
user,
|
|
||||||
},
|
|
||||||
input,
|
|
||||||
});
|
|
||||||
|
|
||||||
const calculateResult = await calculate(requestData);
|
|
||||||
|
|
||||||
const result = transformCalculateResults({
|
|
||||||
calculateInput: input,
|
|
||||||
requestCalculate: requestData,
|
|
||||||
responseCalculate: calculateResult,
|
|
||||||
});
|
|
||||||
|
|
||||||
// TEMP
|
|
||||||
if (ctx.unlimited) {
|
|
||||||
result.__calculateResult = calculateResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: result,
|
|
||||||
success: true,
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -49,14 +49,14 @@ export async function validate({ input, context }: { context: Context; input: Ca
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (validationResult.success === false) {
|
if (validationResult.success === false) {
|
||||||
const error = getMessage(validationResult.error.errors);
|
const message = getMessage(validationResult.error.errors);
|
||||||
|
|
||||||
return { error, success: false };
|
return { message, success: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: '',
|
message: '',
|
||||||
success: true,
|
success: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,15 +34,9 @@ export const OutputDataSchema = z.object({
|
|||||||
|
|
||||||
export type OutputData = z.infer<typeof OutputDataSchema>;
|
export type OutputData = z.infer<typeof OutputDataSchema>;
|
||||||
|
|
||||||
export const CalculateOutputSchema = z.union([
|
export const CalculateOutputSchema = z.object({
|
||||||
z.object({
|
data: OutputDataSchema,
|
||||||
data: OutputDataSchema,
|
success: z.literal(true),
|
||||||
success: z.literal(true),
|
});
|
||||||
}),
|
|
||||||
z.object({
|
|
||||||
error: z.string(),
|
|
||||||
success: z.literal(false),
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
export type CalculateOutput = z.infer<typeof CalculateOutputSchema>;
|
export type CalculateOutput = z.infer<typeof CalculateOutputSchema>;
|
||||||
|
|||||||
@ -34,6 +34,8 @@ import * as price from '@/process/price';
|
|||||||
import * as subsidy from '@/process/subsidy';
|
import * as subsidy from '@/process/subsidy';
|
||||||
import * as supplierAgent from '@/process/supplier-agent';
|
import * as supplierAgent from '@/process/supplier-agent';
|
||||||
import type { CalculationValues } from '@/stores/calculation/values/types';
|
import type { CalculationValues } from '@/stores/calculation/values/types';
|
||||||
|
import { HttpError } from '@/utils/error';
|
||||||
|
import { createTRPCError } from '@/utils/trpc';
|
||||||
import { QueryClient } from '@tanstack/react-query';
|
import { QueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable;
|
const { DEFAULT_FINGAP_ROW, DEFAULT_KASKO_ROW, DEFAULT_OSAGO_ROW } = insuranceTable;
|
||||||
@ -96,70 +98,71 @@ export const quoteRouter = router({
|
|||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
if (!ctx.unlimited) {
|
try {
|
||||||
const validationResult = await validate({
|
if (!ctx.unlimited) {
|
||||||
|
const validationResult = await validate({
|
||||||
|
context: {
|
||||||
|
apolloClient,
|
||||||
|
queryClient,
|
||||||
|
user: ctx.user,
|
||||||
|
},
|
||||||
|
input,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validationResult.success === false) {
|
||||||
|
throw new HttpError(validationResult.message, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let user: Pick<User, 'domainName'> = { domainName: ctx.user.domainName };
|
||||||
|
if (ctx.unlimited && input.values.user) {
|
||||||
|
user = { domainName: input.values.user };
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestData = await createRequestData({
|
||||||
context: {
|
context: {
|
||||||
apolloClient,
|
apolloClient,
|
||||||
queryClient,
|
queryClient,
|
||||||
user: ctx.user,
|
...ctx,
|
||||||
|
user,
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (validationResult.success === false) {
|
const calculateResult = await calculate(requestData);
|
||||||
return {
|
|
||||||
error: validationResult.error,
|
const requestCreateKP = compatRequestCreateKP({
|
||||||
success: false,
|
domainName: user.domainName,
|
||||||
};
|
finGAP: input.fingap,
|
||||||
|
insurance: Object.values(input.insurance.values),
|
||||||
|
calculation: {
|
||||||
|
calculationValues: await compatValues(input.values, { apolloClient }),
|
||||||
|
...calculateResult,
|
||||||
|
preparedPayments: requestData.preparedPayments,
|
||||||
|
additionalData: requestData.additionalData,
|
||||||
|
},
|
||||||
|
elt: input.elt,
|
||||||
|
});
|
||||||
|
|
||||||
|
const createKPResult = await createKP(requestCreateKP);
|
||||||
|
|
||||||
|
const result = transformCalculateResults({
|
||||||
|
calculateInput: input,
|
||||||
|
requestCalculate: requestData,
|
||||||
|
responseCalculate: calculateResult,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (URL_CRM_DOWNLOADKP) {
|
||||||
|
result.values.downloadKp = URL_CRM_DOWNLOADKP?.concat(createKPResult.offerprintformapi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: result,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw createTRPCError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user: Pick<User, 'domainName'> = { domainName: ctx.user.domainName };
|
|
||||||
if (ctx.unlimited && input.values.user) {
|
|
||||||
user = { domainName: input.values.user };
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = await createRequestData({
|
|
||||||
context: {
|
|
||||||
apolloClient,
|
|
||||||
queryClient,
|
|
||||||
...ctx,
|
|
||||||
user,
|
|
||||||
},
|
|
||||||
input,
|
|
||||||
});
|
|
||||||
|
|
||||||
const calculateResult = await calculate(requestData);
|
|
||||||
|
|
||||||
const requestCreateKP = compatRequestCreateKP({
|
|
||||||
domainName: user.domainName,
|
|
||||||
finGAP: input.fingap,
|
|
||||||
insurance: Object.values(input.insurance.values),
|
|
||||||
calculation: {
|
|
||||||
calculationValues: await compatValues(input.values, { apolloClient }),
|
|
||||||
...calculateResult,
|
|
||||||
preparedPayments: requestData.preparedPayments,
|
|
||||||
additionalData: requestData.additionalData,
|
|
||||||
},
|
|
||||||
elt: input.elt,
|
|
||||||
});
|
|
||||||
|
|
||||||
const createKPResult = await createKP(requestCreateKP);
|
|
||||||
|
|
||||||
const result = transformCalculateResults({
|
|
||||||
calculateInput: input,
|
|
||||||
requestCalculate: requestData,
|
|
||||||
responseCalculate: calculateResult,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (URL_CRM_DOWNLOADKP) {
|
|
||||||
result.values.downloadKp = URL_CRM_DOWNLOADKP?.concat(createKPResult.offerprintformapi);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: result,
|
|
||||||
success: true,
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { HttpError } from './error';
|
||||||
import { captureException, withScope } from '@sentry/nextjs';
|
import { captureException, withScope } from '@sentry/nextjs';
|
||||||
import type { AxiosError } from 'axios';
|
import type { AxiosError } from 'axios';
|
||||||
import { isAxiosError } from 'axios';
|
import { isAxiosError } from 'axios';
|
||||||
@ -17,25 +18,28 @@ function getErrorMessage<T extends { error?: string; errors?: string[]; message?
|
|||||||
export async function withHandleError<T>(fn: Promise<T>) {
|
export async function withHandleError<T>(fn: Promise<T>) {
|
||||||
return fn.catch((error_: AxiosError | Error) => {
|
return fn.catch((error_: AxiosError | Error) => {
|
||||||
if (isAxiosError(error_)) {
|
if (isAxiosError(error_)) {
|
||||||
const err = pick(error_, ['code', 'message', 'status', 'cause']);
|
|
||||||
const data = error_.config?.data;
|
|
||||||
const params = error_.config?.params;
|
|
||||||
|
|
||||||
const message = getErrorMessage(error_);
|
const message = getErrorMessage(error_);
|
||||||
const opts = { ...err, data, message, params };
|
|
||||||
|
|
||||||
error_.message += ` | ${message}`;
|
if (error_.response?.status && error_.response?.status >= 500) {
|
||||||
|
const err = pick(error_, ['code', 'message', 'status', 'cause']);
|
||||||
|
const data = error_.config?.data;
|
||||||
|
const params = error_.config?.params;
|
||||||
|
|
||||||
withScope((scope) => {
|
const opts = { ...err, data, message, params };
|
||||||
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
|
||||||
let extra = opts[key];
|
error_.message += ` | ${message}`;
|
||||||
if (key === 'data') extra = JSON.stringify(extra);
|
|
||||||
scope.setExtra(key, extra);
|
withScope((scope) => {
|
||||||
|
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
||||||
|
let extra = opts[key];
|
||||||
|
if (key === 'data') extra = JSON.stringify(extra);
|
||||||
|
scope.setExtra(key, extra);
|
||||||
|
});
|
||||||
|
captureException(error_);
|
||||||
});
|
});
|
||||||
captureException(error_);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(message);
|
throw new HttpError(message, error_.status || error_.response?.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null as unknown as T;
|
return null as unknown as T;
|
||||||
|
|||||||
9
apps/web/utils/error.ts
Normal file
9
apps/web/utils/error.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export class HttpError extends Error {
|
||||||
|
public statusCode: number;
|
||||||
|
|
||||||
|
constructor(message: string, statusCode = 500) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'HttpError';
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
apps/web/utils/trpc.ts
Normal file
38
apps/web/utils/trpc.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { HttpError } from './error';
|
||||||
|
import { TRPCError } from '@trpc/server';
|
||||||
|
import type { TRPC_ERROR_CODE_KEY } from '@trpc/server/rpc';
|
||||||
|
|
||||||
|
const HTTP_CODE_TO_JSONRPC2: Record<number, TRPC_ERROR_CODE_KEY> = {
|
||||||
|
400: 'BAD_REQUEST',
|
||||||
|
401: 'UNAUTHORIZED',
|
||||||
|
403: 'FORBIDDEN',
|
||||||
|
404: 'NOT_FOUND',
|
||||||
|
405: 'METHOD_NOT_SUPPORTED',
|
||||||
|
408: 'TIMEOUT',
|
||||||
|
409: 'CONFLICT',
|
||||||
|
412: 'PRECONDITION_FAILED',
|
||||||
|
413: 'PAYLOAD_TOO_LARGE',
|
||||||
|
429: 'TOO_MANY_REQUESTS',
|
||||||
|
499: 'CLIENT_CLOSED_REQUEST',
|
||||||
|
500: 'INTERNAL_SERVER_ERROR',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createTRPCError(error: unknown) {
|
||||||
|
let code: TRPC_ERROR_CODE_KEY = 'INTERNAL_SERVER_ERROR';
|
||||||
|
let message = '';
|
||||||
|
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
const { statusCode = 500 } = error;
|
||||||
|
code = HTTP_CODE_TO_JSONRPC2[statusCode];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message = error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TRPCError({
|
||||||
|
cause: error,
|
||||||
|
code,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user