refactor after first successful connection
This commit is contained in:
parent
a34bfebcde
commit
6fe0fa1faa
@ -1,4 +1,3 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
export const API_HOSTNAME = window.location.hostname;
|
||||
export const currentDate = DateTime.local().toUTC().toJSDate().toDateString();
|
||||
|
||||
11
src/client/common/urls.js
Normal file
11
src/client/common/urls.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { SERVER_PORT } from 'core/constants/urls';
|
||||
|
||||
export const API_HOSTNAME = window.location.hostname;
|
||||
|
||||
export const getServerUrl = url =>
|
||||
String.prototype.concat(
|
||||
(process.env.NODE_ENV === 'development' &&
|
||||
`http://${API_HOSTNAME}:${SERVER_PORT}`) ||
|
||||
'',
|
||||
url || '',
|
||||
);
|
||||
@ -1,22 +1,22 @@
|
||||
import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client';
|
||||
import axios from 'axios';
|
||||
import { API_HOSTNAME } from 'client/common/constants';
|
||||
import { getServerUrl } from 'client/common/urls';
|
||||
import {
|
||||
CORE_PROXY_URL,
|
||||
CRM_GRAPHQL_PROXY_URL,
|
||||
CRM_GRAPHQL_URL,
|
||||
CRM_GRAPHQL_URL
|
||||
} from 'core/constants/urls';
|
||||
import { convertEntityToOption } from 'core/tools/entities';
|
||||
import { convertJSONToGQLQuery } from 'core/tools/query';
|
||||
import {
|
||||
IGetEntitiesRequest,
|
||||
IRequestToCRMGQL,
|
||||
IGetCalculationRequest,
|
||||
IGetEntitiesRequest,
|
||||
IRequestToCRMGQL
|
||||
} from 'core/types/Calculation/Requests';
|
||||
import {
|
||||
IGetCalculationResponse,
|
||||
IGetEntitiesResponse,
|
||||
IGetUserResponse,
|
||||
IGetUserResponse
|
||||
} from 'core/types/Calculation/Responses';
|
||||
import { IBaseOption } from 'core/types/Calculation/Store/options';
|
||||
import { TCRMEntity } from 'core/types/Entities/crmEntities';
|
||||
@ -28,14 +28,7 @@ const client = new ApolloClient({
|
||||
cache: new InMemoryCache(),
|
||||
|
||||
link: new HttpLink({
|
||||
uri:
|
||||
process.env.NODE_ENV !== 'development'
|
||||
? String.prototype.concat('/proxy', CRM_GRAPHQL_PROXY_URL)
|
||||
: String.prototype.concat(
|
||||
`http://${API_HOSTNAME}:3001`,
|
||||
'/proxy',
|
||||
CRM_GRAPHQL_PROXY_URL,
|
||||
),
|
||||
uri: getServerUrl(String.prototype.concat('/proxy', CRM_GRAPHQL_PROXY_URL)),
|
||||
}),
|
||||
|
||||
defaultOptions: {
|
||||
@ -61,23 +54,17 @@ class CalculationService {
|
||||
new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post<IGetCalculationResponse>(
|
||||
String.prototype.concat(
|
||||
(process.env.NODE_ENV !== 'development' &&
|
||||
`http://${API_HOSTNAME}:3001`) ||
|
||||
'',
|
||||
'/proxy',
|
||||
CORE_PROXY_URL,
|
||||
'/api',
|
||||
'/v1',
|
||||
'/calculation',
|
||||
'/calculate',
|
||||
getServerUrl(
|
||||
String.prototype.concat(
|
||||
'/proxy',
|
||||
CORE_PROXY_URL,
|
||||
'/api',
|
||||
'/v1',
|
||||
'/calculation',
|
||||
'/calculate',
|
||||
),
|
||||
),
|
||||
{
|
||||
preparedValues: preparedData.preparedValues,
|
||||
preparedPayments: {
|
||||
Rows: preparedData.preparedPayments,
|
||||
},
|
||||
},
|
||||
preparedData,
|
||||
)
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
|
||||
@ -1,24 +1,22 @@
|
||||
import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools';
|
||||
import valuesConstants from 'core/constants/values';
|
||||
import {
|
||||
PreparedPayments,
|
||||
PreparedValues,
|
||||
} from 'core/types/Calculation/Prepare';
|
||||
import { PreparedValues } from 'core/types/Calculation/Prepare';
|
||||
import { IGetCalculationRequest } from 'core/types/Calculation/Requests';
|
||||
import { DateTime } from 'luxon';
|
||||
import { ICalculationStore } from 'core/types/Calculation/Store';
|
||||
import { DateTime } from 'luxon';
|
||||
import { PaymentRow } from './../../core/types/Calculation/Prepare';
|
||||
|
||||
export const prepareCalculationData = ({
|
||||
calculationStore,
|
||||
}: {
|
||||
calculationStore: ICalculationStore;
|
||||
}): any => {
|
||||
}): IGetCalculationRequest => {
|
||||
const currentDate = DateTime.local().toUTC().toJSDate();
|
||||
|
||||
const { values, options, tables } = calculationStore;
|
||||
|
||||
//@ts-ignore
|
||||
let preparedPayments: PreparedPayments = Array.from(
|
||||
let preparedPaymentsRows: PaymentRow[] = Array.from(
|
||||
{ length: values.leasingPeriod },
|
||||
() => ({
|
||||
numberPayment: 0,
|
||||
@ -37,10 +35,10 @@ export const prepareCalculationData = ({
|
||||
);
|
||||
|
||||
for (let i = 0; i < values.leasingPeriod; i++) {
|
||||
preparedPayments[i].numberPayment = i + 1;
|
||||
preparedPayments[i].percentPayment =
|
||||
preparedPaymentsRows[i].numberPayment = i + 1;
|
||||
preparedPaymentsRows[i].percentPayment =
|
||||
i === 0 ? 0 : tables.tablePayments.rows[i].paymentRelation?.value;
|
||||
preparedPayments[i].sumPayment = 0;
|
||||
preparedPaymentsRows[i].sumPayment = 0;
|
||||
|
||||
if (tracker) {
|
||||
if (tracker.evo_planpayments && tracker.evo_planpayments.length > 0) {
|
||||
@ -48,11 +46,11 @@ export const prepareCalculationData = ({
|
||||
x => x.evo_name === (i + 1).toString(),
|
||||
);
|
||||
if (evo_planpayment) {
|
||||
preparedPayments[i].gpsBasePayment =
|
||||
preparedPaymentsRows[i].gpsBasePayment =
|
||||
(evo_planpayment.evo_cost_price_telematics_withoutnds || 0) +
|
||||
(evo_planpayment.evo_cost_equipment_withoutnds || 0);
|
||||
|
||||
preparedPayments[i].gpsCostPayment =
|
||||
preparedPaymentsRows[i].gpsCostPayment =
|
||||
evo_planpayment.evo_cost_telematics_withoutnds || 0;
|
||||
}
|
||||
}
|
||||
@ -64,11 +62,11 @@ export const prepareCalculationData = ({
|
||||
x => x.evo_name === (i + 1).toString(),
|
||||
);
|
||||
if (evo_planpayment) {
|
||||
preparedPayments[i].tlmBasePayment =
|
||||
preparedPaymentsRows[i].tlmBasePayment =
|
||||
(evo_planpayment.evo_cost_price_telematics_withoutnds || 0) +
|
||||
(evo_planpayment.evo_cost_equipment_withoutnds || 0);
|
||||
|
||||
preparedPayments[i].tlmCostPayment =
|
||||
preparedPaymentsRows[i].tlmCostPayment =
|
||||
evo_planpayment.evo_cost_telematics_withoutnds || 0;
|
||||
}
|
||||
}
|
||||
@ -450,10 +448,10 @@ export const prepareCalculationData = ({
|
||||
(preparedValues.trackerCost || 0) +
|
||||
(preparedValues.tLMCost || 0) +
|
||||
preparedValues.transportTaxGr +
|
||||
preparedPayments
|
||||
preparedPaymentsRows
|
||||
.map(x => x.tlmCostPayment || 0)
|
||||
.reduce((a, b) => a + b, 0) +
|
||||
preparedPayments
|
||||
preparedPaymentsRows
|
||||
.map(x => x.gpsCostPayment || 0)
|
||||
.reduce((a, b) => a + b, 0)) *
|
||||
preparedValues.leasing0K -
|
||||
@ -676,10 +674,10 @@ export const prepareCalculationData = ({
|
||||
plPrice +
|
||||
trackerCost +
|
||||
tLMCost +
|
||||
preparedPayments
|
||||
preparedPaymentsRows
|
||||
.map(x => x.tlmCostPayment || 0)
|
||||
.reduce((a, b) => a + b, 0) +
|
||||
preparedPayments
|
||||
preparedPaymentsRows
|
||||
.map(x => x.gpsCostPayment || 0)
|
||||
.reduce((a, b) => a + b, 0) +
|
||||
registration +
|
||||
@ -733,7 +731,7 @@ export const prepareCalculationData = ({
|
||||
firstPaymentSum;
|
||||
|
||||
return {
|
||||
preparedPayments,
|
||||
preparedPayments: { Rows: preparedPaymentsRows },
|
||||
preparedValues,
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export const API_PORT = 3001;
|
||||
export const SERVER_PORT = 3001;
|
||||
export const CRM_GRAPHQL_URL = 'http://crmgraphql-dev.evoleasing.ru';
|
||||
export const CRM_GRAPHQL_PROXY_URL = '/crmgraphql';
|
||||
export const CORE_URL = 'http://localhost:5000';
|
||||
@ -101,4 +101,4 @@ export interface PaymentRow {
|
||||
tlmCostPayment?: number;
|
||||
}
|
||||
|
||||
export type PreparedPayments = PaymentRow[];
|
||||
export type PreparedPayments = { Rows: PaymentRow[] };
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { ICalculationStore } from 'core/types/Calculation/Store';
|
||||
import { CRMEntityNames } from 'core/types/Entities/crmEntityNames';
|
||||
import { TEntityQuery } from '../Entities/query';
|
||||
import {
|
||||
PreparedPayments,
|
||||
PreparedValues,
|
||||
} from 'core/types/Calculation/Prepare';
|
||||
import { CRMEntityNames } from 'core/types/Entities/crmEntityNames';
|
||||
import { TEntityQuery } from '../Entities/query';
|
||||
|
||||
export interface IGetEntitiesRequest {
|
||||
queries: TEntityQuery[];
|
||||
|
||||
@ -2,13 +2,12 @@ import axios from 'axios';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './client/App';
|
||||
import './index.css';
|
||||
import * as serviceWorker from './client/serviceWorker';
|
||||
import { API_PORT } from './core/constants/urls';
|
||||
import { API_HOSTNAME } from 'client/common/constants';
|
||||
import './index.css';
|
||||
import { getServerUrl } from 'client/common/urls';
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
axios.defaults.baseURL = `http://${API_HOSTNAME}:${API_PORT}`;
|
||||
axios.defaults.baseURL = getServerUrl();
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
|
||||
@ -7,9 +7,9 @@ import helmet from 'helmet';
|
||||
import morgan from 'morgan';
|
||||
import path from 'path';
|
||||
import 'reflect-metadata';
|
||||
import { API_PORT } from '../core/constants/urls';
|
||||
import routes from './routes';
|
||||
import ntlm from 'express-ntlm';
|
||||
import { SERVER_PORT } from './../core/constants/urls';
|
||||
|
||||
const isDevelopmentMode = process.env.NODE_ENV === 'development';
|
||||
|
||||
@ -56,7 +56,7 @@ app.get('*', function (req, res) {
|
||||
});
|
||||
/**CLIENT */
|
||||
|
||||
console.log('checking port', API_PORT);
|
||||
app.listen(API_PORT, () => {
|
||||
console.log(`Server now listening on port: ${API_PORT}`);
|
||||
console.log('checking port', SERVER_PORT);
|
||||
app.listen(SERVER_PORT, () => {
|
||||
console.log(`Server now listening on port: ${SERVER_PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user