Compare commits
2 Commits
dev
...
release/dy
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1652c47cea | ||
|
|
d013be319f |
@ -47,6 +47,8 @@ ARG URL_CORE_CALCULATE_DIRECT
|
||||
ARG URL_1C_TRANSTAX_DIRECT
|
||||
ARG URL_ELT_OSAGO_DIRECT
|
||||
ARG URL_ELT_KASKO_DIRECT
|
||||
ARG USERNAME_1C_TRANSTAX
|
||||
ARG PASSWORD_1C_TRANSTAX
|
||||
RUN pnpm dotenv -v NODE_ENV=production -e .env turbo run prebuild --filter=web...
|
||||
RUN pnpm dotenv -e .env turbo run build --filter=web...
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
export type RequestTransTax = {
|
||||
CalcDate: string;
|
||||
CarCategory: string;
|
||||
OKTMO: string;
|
||||
calcDate: Date;
|
||||
carCategory: string;
|
||||
power: number;
|
||||
year: number;
|
||||
Power: number;
|
||||
Year: number;
|
||||
};
|
||||
export type ResponseTransTax = {
|
||||
error: string;
|
||||
tax: number;
|
||||
Error: string;
|
||||
Tax: number;
|
||||
TaxRate: number;
|
||||
};
|
||||
|
||||
@ -2,6 +2,8 @@ const { z } = require('zod');
|
||||
|
||||
const envSchema = z.object({
|
||||
BASE_PATH: z.string().optional().default(''),
|
||||
DEV_AUTH_TOKEN: z.string().optional(),
|
||||
PASSWORD_1C_TRANSTAX: z.string(),
|
||||
PORT: z.string().optional(),
|
||||
SENTRY_AUTH_TOKEN: z.string(),
|
||||
SENTRY_DSN: z.string(),
|
||||
@ -11,7 +13,6 @@ const envSchema = z.object({
|
||||
URL_CACHE_GET_QUERIES_DIRECT: z.string().default('http://api:3001/proxy/get-queries'),
|
||||
URL_CACHE_GET_QUERY_DIRECT: z.string().default('http://api:3001/proxy/get-query'),
|
||||
URL_CACHE_RESET_QUERIES_DIRECT: z.string().default('http://api:3001/proxy/reset'),
|
||||
DEV_AUTH_TOKEN: z.string().optional(),
|
||||
URL_CORE_CALCULATE_DIRECT: z.string(),
|
||||
URL_CORE_FINGAP_DIRECT: z.string(),
|
||||
URL_CRM_CREATEKP_DIRECT: z.string(),
|
||||
@ -22,6 +23,7 @@ const envSchema = z.object({
|
||||
URL_ELT_OSAGO_DIRECT: z.string(),
|
||||
URL_GET_USER_DIRECT: z.string(),
|
||||
USE_DEV_COLORS: z.unknown().optional().transform(Boolean),
|
||||
USERNAME_1C_TRANSTAX: z.string(),
|
||||
});
|
||||
|
||||
module.exports = envSchema;
|
||||
|
||||
@ -11,6 +11,7 @@ const publicRuntimeConfigSchema = envSchema.pick({
|
||||
const serverRuntimeConfigSchema = envSchema.pick({
|
||||
BASE_PATH: true,
|
||||
DEV_AUTH_TOKEN: true,
|
||||
PASSWORD_1C_TRANSTAX: true,
|
||||
PORT: true,
|
||||
SENTRY_DSN: true,
|
||||
SENTRY_ENVIRONMENT: true,
|
||||
@ -27,6 +28,7 @@ const serverRuntimeConfigSchema = envSchema.pick({
|
||||
URL_ELT_KASKO_DIRECT: true,
|
||||
URL_ELT_OSAGO_DIRECT: true,
|
||||
URL_GET_USER_DIRECT: true,
|
||||
USERNAME_1C_TRANSTAX: true,
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -39,20 +39,23 @@ export const handlers = [
|
||||
rest.post(URL_1C_TRANSTAX, (req, res, ctx) =>
|
||||
res(
|
||||
ctx.json({
|
||||
error: null,
|
||||
tax: _.random(100000, 200000),
|
||||
Error: null,
|
||||
Tax: _.random(100000, 200000),
|
||||
})
|
||||
)
|
||||
),
|
||||
rest.post(URL_ELT_OSAGO, async (req, res, ctx) => res(
|
||||
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_KASKO, async (req, res, ctx) => res(
|
||||
)
|
||||
),
|
||||
rest.post(URL_ELT_KASKO, async (req, res, ctx) =>
|
||||
res(
|
||||
ctx.json({
|
||||
requestId: _.random(3000000, 4000000).toString(),
|
||||
skCalcId: _.random(50000000, 60000000).toString(),
|
||||
@ -67,7 +70,8 @@ export const handlers = [
|
||||
],
|
||||
totalFranchise: _.random(20000, 40000),
|
||||
})
|
||||
)),
|
||||
)
|
||||
),
|
||||
|
||||
// rest.post(URL_CRM_GRAPHQL, (req, res, ctx) => {
|
||||
// return res(ctx.status(503));
|
||||
|
||||
@ -66,10 +66,10 @@ module.exports = withSentryConfig(
|
||||
destination: env.URL_CORE_FINGAP_DIRECT,
|
||||
source: urls.URL_CORE_FINGAP_PROXY,
|
||||
},
|
||||
{
|
||||
destination: env.URL_1C_TRANSTAX_DIRECT,
|
||||
source: urls.URL_1C_TRANSTAX_PROXY,
|
||||
},
|
||||
// {
|
||||
// destination: env.URL_1C_TRANSTAX_DIRECT,
|
||||
// source: urls.URL_1C_TRANSTAX_PROXY,
|
||||
// },
|
||||
{
|
||||
destination: env.URL_ELT_KASKO_DIRECT,
|
||||
source: urls.URL_ELT_KASKO_PROXY,
|
||||
|
||||
38
apps/web/pages/api/1c/transtax.ts
Normal file
38
apps/web/pages/api/1c/transtax.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import type { ResponseTransTax } from '@/api/1c/types';
|
||||
import { serverRuntimeConfigSchema } from '@/config/schema/runtime-config';
|
||||
import { withHandleError } from '@/utils/axios';
|
||||
import type { HttpError } from '@/utils/error';
|
||||
import axios from 'axios';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import getConfig from 'next/config';
|
||||
|
||||
const { serverRuntimeConfig } = getConfig();
|
||||
const { USERNAME_1C_TRANSTAX, PASSWORD_1C_TRANSTAX, URL_1C_TRANSTAX_DIRECT } =
|
||||
serverRuntimeConfigSchema.parse(serverRuntimeConfig);
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const abortController = new AbortController();
|
||||
|
||||
req.on('close', () => {
|
||||
abortController.abort();
|
||||
});
|
||||
|
||||
const params = req.body as ResponseTransTax;
|
||||
|
||||
withHandleError(
|
||||
axios.get<ResponseTransTax>(URL_1C_TRANSTAX_DIRECT, {
|
||||
auth: {
|
||||
password: PASSWORD_1C_TRANSTAX,
|
||||
username: USERNAME_1C_TRANSTAX,
|
||||
},
|
||||
params,
|
||||
signal: abortController.signal,
|
||||
})
|
||||
)
|
||||
.then(({ data }) => res.json(data))
|
||||
.catch((error) => {
|
||||
const _err = error as HttpError;
|
||||
|
||||
return res.json({ message: _err.message });
|
||||
});
|
||||
}
|
||||
@ -9,7 +9,6 @@ import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { getCurrentDateString } from '@/utils/date';
|
||||
import { normalizeOptions } from '@/utils/entity';
|
||||
import { disposableReaction } from '@/utils/mobx';
|
||||
import dayjs from 'dayjs';
|
||||
import { reaction } from 'mobx';
|
||||
|
||||
export function common({ store, apolloClient, queryClient }: ProcessContext) {
|
||||
@ -186,18 +185,16 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) {
|
||||
const carCategory = getCarCategory(objectTypeTax);
|
||||
|
||||
if (OKTMO) {
|
||||
const currentDate = dayjs().utc(false).toDate();
|
||||
|
||||
const response = await queryClient.fetchQuery(
|
||||
['1c', 'trans-tax', carCategory, leaseObjectMotorPower, leaseObjectYear],
|
||||
['1c', 'trans-tax', carCategory, leaseObjectMotorPower, leaseObjectYear, OKTMO],
|
||||
(context) =>
|
||||
getTransTax(
|
||||
{
|
||||
CalcDate: getCurrentDateString(),
|
||||
CarCategory: carCategory,
|
||||
OKTMO,
|
||||
calcDate: currentDate,
|
||||
carCategory,
|
||||
power: leaseObjectMotorPower,
|
||||
year: leaseObjectYear,
|
||||
Power: leaseObjectMotorPower,
|
||||
Year: leaseObjectYear,
|
||||
},
|
||||
context
|
||||
),
|
||||
@ -206,8 +203,8 @@ export function common({ store, apolloClient, queryClient }: ProcessContext) {
|
||||
}
|
||||
);
|
||||
|
||||
if (response?.tax) {
|
||||
$calculation.element('tbxVehicleTaxInYear').setValue(response.tax);
|
||||
if (response?.Tax) {
|
||||
$calculation.element('tbxVehicleTaxInYear').setValue(response.Tax);
|
||||
} else {
|
||||
$calculation.element('tbxVehicleTaxInYear').resetValue();
|
||||
}
|
||||
|
||||
@ -4,10 +4,17 @@ import type { AxiosError } from 'axios';
|
||||
import { isAxiosError } from 'axios';
|
||||
import { pick } from 'radash';
|
||||
|
||||
function getErrorMessage<
|
||||
T extends { error?: string; errors?: string[]; fullMessage?: string; message?: string }
|
||||
>(error: AxiosError<T>) {
|
||||
type ResponseError = {
|
||||
Error?: string;
|
||||
error?: string;
|
||||
errors?: string[];
|
||||
fullMessage?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
function getErrorMessage<T extends ResponseError>(error: AxiosError<T>) {
|
||||
return (
|
||||
error.response?.data?.Error ||
|
||||
error.response?.data?.error ||
|
||||
error.response?.data?.errors?.[0] ||
|
||||
error.response?.data.fullMessage ||
|
||||
|
||||
@ -16,6 +16,8 @@ services:
|
||||
- URL_CORE_FINGAP_DIRECT=${URL_CORE_FINGAP_DIRECT}
|
||||
- URL_CORE_CALCULATE_DIRECT=${URL_CORE_CALCULATE_DIRECT}
|
||||
- URL_1C_TRANSTAX_DIRECT=${URL_1C_TRANSTAX_DIRECT}
|
||||
- USERNAME_1C_TRANSTAX=${USERNAME_1C_TRANSTAX}
|
||||
- PASSWORD_1C_TRANSTAX=${PASSWORD_1C_TRANSTAX}
|
||||
- URL_ELT_OSAGO_DIRECT=${URL_ELT_OSAGO_DIRECT}
|
||||
- URL_ELT_KASKO_DIRECT=${URL_ELT_KASKO_DIRECT}
|
||||
build:
|
||||
@ -34,6 +36,8 @@ services:
|
||||
- URL_CORE_FINGAP_DIRECT=${URL_CORE_FINGAP_DIRECT}
|
||||
- URL_CORE_CALCULATE_DIRECT=${URL_CORE_CALCULATE_DIRECT}
|
||||
- URL_1C_TRANSTAX_DIRECT=${URL_1C_TRANSTAX_DIRECT}
|
||||
- USERNAME_1C_TRANSTAX=${USERNAME_1C_TRANSTAX}
|
||||
- PASSWORD_1C_TRANSTAX=${PASSWORD_1C_TRANSTAX}
|
||||
- URL_ELT_OSAGO_DIRECT=${URL_ELT_OSAGO_DIRECT}
|
||||
- URL_ELT_KASKO_DIRECT=${URL_ELT_KASKO_DIRECT}
|
||||
context: .
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user