refactor project structure

This commit is contained in:
Chika 2020-11-19 18:31:12 +03:00
parent 0bfcfe1281
commit d6917f44b7
31 changed files with 274 additions and 256 deletions

View File

@ -4,6 +4,6 @@ import React from 'react';
export default {
404: () => <Result status="404" title="404" subTitle="Ой! Тут ничего нет." />,
500: () => (
<Result status="500" title="500" subTitle={'Ой! Что-то сломалось.'} />
<Result status="500" title="" subTitle={'Ой! Что-то сломалось.'} />
),
};

View File

@ -1,4 +1,3 @@
import { Divider } from 'antd';
import { renderGroups } from 'client/Containers/Calculation/lib/renderSections';
import Background from 'client/Elements/Background';
import { Box, Flex } from 'client/UIKit/grid';

View File

@ -1,137 +0,0 @@
import { gql } from '@apollo/client';
import { currentDate } from 'client/tools/date';
import CalculationService from 'client/services/CalculationService';
import CalculationStore from 'client/stores/CalculationStore';
import { getUser } from 'client/tools/user';
import initialOptions from 'core/Data/initialOptions';
export default () =>
new Promise((resolve, reject) => {
getUser().then(({ UserName, DomainName }) => {
Promise.all([
CalculationService.getEntities({
queries: initialOptions,
}),
CalculationService.crmgqlquery({
query: gql`
query($statecode: Int, $currentDate: DateTime) {
evo_impairment_group: evo_impairment_groups(
statecode: $statecode
) {
evo_impairment_groupid
evo_name
}
evo_currencychange: evo_currencychanges(
statecode: $statecode
evo_coursedate_param: { eq: $currentDate }
) {
evo_currencychange
evo_ref_transactioncurrency
}
evo_coefficient: evo_coefficients(
statecode: $statecode
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
evo_correction_coefficient
evo_graph_type
evo_season_type
evo_job_titleid
evo_sot_coefficient_typeid
evo_sot_coefficient
evo_corfficient_type
evo_min_period
evo_max_period
evo_graph_type
evo_season_type
evo_correction_coefficient
evo_client_riskid
evo_client_typeid
evo_risk_delta
evo_leasingobject_types {
evo_name
evo_id
evo_leasingobject_typeid
}
}
evo_sot_coefficient_type: evo_sot_coefficient_types(
statecode: $statecode
) {
evo_id
evo_name
evo_sot_coefficient_typeid
}
evo_job_title: evo_job_titles(statecode: $statecode) {
evo_id
evo_name
evo_job_titleid
}
}
`,
variables: {
statecode: 0,
currentDate,
},
}),
CalculationService.crmgqlquery({
query: gql`
query($username: String) {
systemuser(domainname: $username) {
evo_job_titleid
businessunitid
firstname
lastname
fullname
}
}
`,
variables: { username: `${DomainName}\\${UserName}` },
}),
CalculationService.getEntities({
queries: [
{
//@ts-ignore
alias: 'insuranceCompany',
entityName: 'account',
where: { evo_account_type: 100000002, statecode: 0 },
fields: ['accountid', 'name', 'evo_type_ins_policy'],
many: true,
toOption: true,
},
],
}),
])
.then(
([
{ entities: initialOptions },
{ entities: staticEntities },
{
entities: { systemuser },
},
{ entities: insuranceCompanies },
]) => {
CalculationStore.applyOptions(initialOptions);
CalculationStore.applyStaticData(staticEntities);
CalculationStore.applyStaticData({ systemuser: [systemuser] });
CalculationStore.setTableColumns('tableInsurance')({
options: { ...insuranceCompanies },
});
var supplierCurrency = CalculationStore.options.selectSupplierCurrency?.find(
x => x.isocurrencycode === 'RUB',
);
if (supplierCurrency)
CalculationStore.setValue(
'supplierCurrency',
supplierCurrency.transactioncurrencyid,
);
resolve();
},
)
.catch(err => {
reject(err);
throw err;
});
});
});

View File

@ -0,0 +1,70 @@
import CrmService from 'client/services/CrmService';
import CalculationStore from 'client/stores/CalculationStore';
import { currentDate } from 'client/tools/date';
import { getUser } from 'client/tools/user';
import insuranceQuery from './queries/insuranceQuery';
import optionsQuery from './queries/optionsQuery';
import staticDataQuery from './queries/staticDataQuery';
import systemUserQuery from './queries/systemUserQuery';
export default () =>
new Promise((resolve, reject) => {
getUser()
.then(({ UserName, DomainName }) => {
Promise.all([
CrmService.getEntities({
queries: optionsQuery,
}),
CrmService.crmgqlquery({
query: staticDataQuery,
variables: {
statecode: 0,
currentDate,
},
}),
CrmService.crmgqlquery({
query: systemUserQuery,
variables: { username: `${DomainName}\\${UserName}` },
}),
CrmService.getEntities({
queries: insuranceQuery,
}),
])
.then(
([
{ entities: initialOptions },
{ entities: staticEntities },
{
entities: { systemuser },
},
{ entities: insuranceCompanies },
]) => {
CalculationStore.applyOptions(initialOptions);
CalculationStore.applyStaticData(staticEntities);
CalculationStore.applyStaticData({ systemuser: [systemuser] });
CalculationStore.setTableColumns('tableInsurance')({
options: { ...insuranceCompanies },
});
var supplierCurrency = CalculationStore.options.selectSupplierCurrency?.find(
x => x.isocurrencycode === 'RUB',
);
if (supplierCurrency)
CalculationStore.setValue(
'supplierCurrency',
supplierCurrency.transactioncurrencyid,
);
resolve();
},
)
.catch(err => {
reject(err);
throw err;
});
})
.catch(err => {
reject(err);
throw err;
});
});

View File

@ -0,0 +1,14 @@
import { TEntityQuery } from 'core/types/Entities/query';
const insuranceQuery: TEntityQuery[] = [
{
//@ts-ignore
alias: 'insuranceCompany',
entityName: 'account',
where: { evo_account_type: 100000002, statecode: 0 },
fields: ['accountid', 'name', 'evo_type_ins_policy'],
many: true,
toOption: true,
},
];
export default insuranceQuery;

View File

@ -1,7 +1,7 @@
import { TEntityQuery } from 'core/types/Entities/query';
import { currentDate } from 'client/tools/date';
const initialOptions: TEntityQuery[] = [
const initialOptionsQuery: TEntityQuery[] = [
{
alias: 'selectLead',
entityName: 'lead',
@ -453,4 +453,4 @@ const initialOptions: TEntityQuery[] = [
},
];
export default initialOptions;
export default initialOptionsQuery;

View File

@ -0,0 +1,53 @@
import { gql } from '@apollo/client';
export default gql`
query($statecode: Int, $currentDate: DateTime) {
evo_impairment_group: evo_impairment_groups(statecode: $statecode) {
evo_impairment_groupid
evo_name
}
evo_currencychange: evo_currencychanges(
statecode: $statecode
evo_coursedate_param: { eq: $currentDate }
) {
evo_currencychange
evo_ref_transactioncurrency
}
evo_coefficient: evo_coefficients(
statecode: $statecode
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
evo_correction_coefficient
evo_graph_type
evo_season_type
evo_job_titleid
evo_sot_coefficient_typeid
evo_sot_coefficient
evo_corfficient_type
evo_min_period
evo_max_period
evo_graph_type
evo_season_type
evo_correction_coefficient
evo_client_riskid
evo_client_typeid
evo_risk_delta
evo_leasingobject_types {
evo_name
evo_id
evo_leasingobject_typeid
}
}
evo_sot_coefficient_type: evo_sot_coefficient_types(statecode: $statecode) {
evo_id
evo_name
evo_sot_coefficient_typeid
}
evo_job_title: evo_job_titles(statecode: $statecode) {
evo_id
evo_name
evo_job_titleid
}
}
`;

View File

@ -0,0 +1,13 @@
import { gql } from '@apollo/client';
export default gql`
query($username: String) {
systemuser(domainname: $username) {
evo_job_titleid
businessunitid
firstname
lastname
fullname
}
}
`;

View File

@ -1,7 +1,7 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { ValidateStatus } from 'antd/lib/form/FormItem';
import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'core/constants/errorMessages';
import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'client/constants/errorMessages';
import { ElementsNames } from 'core/types/Calculation/Store/elements';
import {
TableNames,

View File

@ -1,5 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { DEFAULT_DEBOUNCE_DELAY } from 'core/constants/debounce';
import { DEFAULT_DEBOUNCE_DELAY } from 'client/constants/debounce';
import { useEffect, useState } from 'react';
import { useDebounce } from 'use-debounce/lib';
import { useStores } from '../useStores';

View File

@ -0,0 +1,46 @@
import axios from 'axios';
import { getServerUrl } from 'client/common/urls';
import { CORE_PROXY_URL } from 'core/constants/urls';
import { IGetCalculationRequest } from 'core/types/Calculation/Requests';
import {
IGetCalculationResponse,
IGetUserResponse,
} from 'core/types/Calculation/Responses';
export default class {
static getUser = (): Promise<IGetUserResponse> =>
new Promise((resolve, reject) => {
axios
.get('/api/users/getUser')
.then(res => {
resolve(res.data);
})
.catch(err => {
reject(err);
});
});
static calculate = (
preparedData: IGetCalculationRequest,
): Promise<IGetCalculationResponse> =>
new Promise((resolve, reject) => {
axios
.post<IGetCalculationResponse>(
getServerUrl(
'/proxy',
CORE_PROXY_URL,
'/api',
'/v1',
'/calculation',
'/calculate',
),
preparedData,
)
.then(res => {
resolve(res.data);
})
.catch(err => {
reject(err);
});
});
}

View File

@ -0,0 +1,19 @@
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
import { getServerUrl } from 'client/common/urls';
import { CRM_URL, CRM_PROXY_URL } from 'core/constants/urls';
export default new ApolloClient({
uri: CRM_URL,
cache: new InMemoryCache(),
link: new HttpLink({
uri: getServerUrl('/proxy', CRM_PROXY_URL),
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
},
});

View File

@ -1,81 +1,23 @@
import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client';
import { gql } from '@apollo/client';
import axios from 'axios';
import { getServerUrl } from 'client/common/urls';
import { CORE_PROXY_URL, CRM_PROXY_URL, CRM_URL } from 'core/constants/urls';
import { convertEntityToOption } from 'core/tools/entities';
import { convertJSONToGQLQuery } from 'core/tools/query';
import { CRM_PROXY_URL } from 'core/constants/urls';
import { convertEntityToOption } from './tools/entity';
import { convertJSONToGQLQuery } from './tools/query';
import {
IGetCalculationRequest,
ICreateKpRequest,
IGetEntitiesRequest,
IMutateToCRMGQL,
IQueryToCRMGQL,
} from 'core/types/Calculation/Requests';
import {
IGetCalculationResponse,
IGetEntitiesResponse,
IGetUserResponse,
} from 'core/types/Calculation/Responses';
import { IGetEntitiesResponse } from 'core/types/Calculation/Responses';
import { IBaseOption } from 'core/types/Calculation/Store/options';
import { IQuote, TCRMEntity } from 'core/types/Entities/crmEntities';
import { TEntities } from 'core/types/Entities/crmEntityNames';
import client from './client';
import { isPlural, singular } from 'pluralize';
import {
ICreateKpRequest,
IMutateToCRMGQL,
} from './../../core/types/Calculation/Requests';
const client = new ApolloClient({
uri: CRM_URL,
cache: new InMemoryCache(),
link: new HttpLink({
uri: getServerUrl('/proxy', CRM_PROXY_URL),
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
},
});
class CalculationService {
static getUser = (): Promise<IGetUserResponse> =>
new Promise((resolve, reject) => {
axios
.get('/api/users/getUser')
.then(res => {
resolve(res.data);
})
.catch(err => {
throw err;
});
});
static calculate = (
preparedData: IGetCalculationRequest,
): Promise<IGetCalculationResponse> =>
new Promise((resolve, reject) => {
axios
.post<IGetCalculationResponse>(
getServerUrl(
'/proxy',
CORE_PROXY_URL,
'/api',
'/v1',
'/calculation',
'/calculate',
),
preparedData,
)
.then(res => {
resolve(res.data);
})
.catch(err => {
reject(err);
});
});
export default class {
static crmgqlquery = ({
query,
toOptions,
@ -252,5 +194,3 @@ class CalculationService {
});
});
}
export default CalculationService;

View File

@ -1,5 +1,5 @@
import { TCRMEntity } from 'core/types/Entities/crmEntities';
import { TEntities } from '../types/Entities/crmEntityNames';
import { TEntities } from 'core/types/Entities/crmEntityNames';
const propsMap: TEntities<{
name: keyof TCRMEntity;

View File

@ -1,7 +1,7 @@
import propsMap from '../Data/propsMap';
import { IBaseOption } from '../types/Calculation/Store/options';
import { TCRMEntity } from '../types/Entities/crmEntities';
import { CRMEntityNames } from '../types/Entities/crmEntityNames';
import propsMap from '../propsMap';
import { IBaseOption } from 'core/types/Calculation/Store/options';
import { TCRMEntity } from 'core/types/Entities/crmEntities';
import { CRMEntityNames } from 'core/types/Entities/crmEntityNames';
export function convertEntityToOption(
entity: TCRMEntity,

View File

@ -1,10 +1,11 @@
import { stringifyObject } from 'core/tools/string';
import {
ComparisonOperators,
TBaseEntityQuery,
TEntitiesKeys,
TEntityQuery,
TWhere,
ComparisonOperators,
} from 'core/types/Entities/query';
import { TBaseEntityQuery, TEntitiesKeys } from './../types/Entities/query';
import { stringifyObject } from './string';
import { plural } from 'pluralize';
const convert = {

View File

@ -1,4 +1,4 @@
import initialTables from 'core/config/initialTables';
import initialTables from 'client/stores/CalculationStore/config/initialTables';
const tablesData = {
tables: initialTables,

View File

@ -1,7 +1,7 @@
import initialFilters from 'core/config/initialFilters';
import initialOptions from 'core/config/initialOptions';
import initialStatuses from 'core/config/initialStatuses';
import initialValues from 'core/config/initialValues';
import initialFilters from 'client/stores/CalculationStore/config/initialFilters';
import initialOptions from 'client/stores/CalculationStore/config/initialOptions';
import initialStatuses from 'client/stores/CalculationStore/config/initialStatuses';
import initialValues from 'client/stores/CalculationStore/config/initialValues';
const valuesData = {
values: initialValues,

View File

@ -3,7 +3,7 @@ import { gql } from '@apollo/client';
import { message } from 'antd';
import { openNotification } from 'client/Elements/Notification';
import CalculationService from 'client/services/CalculationService';
import { prepareCalculationData } from 'client/services/prepareData';
import prepareCalculationData from './lib/prepareData';
import CalculationStore from 'client/stores/CalculationStore';
import { getUser } from 'client/tools/user';
import { TAction } from 'core/types/Calculation/Store/effect';

View File

@ -1,11 +1,11 @@
import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools';
import { calcPrice } from './tools';
import valuesConstants from 'core/constants/values';
import { PaymentRow, PreparedValues } from 'core/types/Calculation/Prepare';
import { IGetCalculationRequest } from 'core/types/Calculation/Requests';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { DateTime } from 'luxon';
export const prepareCalculationData = ({
export default ({
calculationStore,
}: {
calculationStore: ICalculationStore;

View File

@ -1,13 +1,13 @@
import { gql } from '@apollo/client';
import { openNotification } from 'client/Elements/Notification';
import CalculationService from 'client/services/CalculationService';
import CrmService from 'client/services/CrmService';
import { currentDate } from 'client/tools/date';
import { shift, shiftRight } from 'core/tools/array';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { Status } from 'core/types/statuses';
import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables';
import { Status } from 'core/types/statuses';
import { toJS } from 'mobx';
import { calcPrice, calculatePerc, calculateRub } from './lib/tools';
import { gql } from '@apollo/client';
import { currentDate } from 'client/tools/date';
const reactionEffects: IReactionEffect[] = [
calculationStore => ({
@ -49,7 +49,7 @@ const reactionEffects: IReactionEffect[] = [
}
if (lead.leadid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($leadid: Uuid) {
quote: quotes(evo_leadid: $leadid) {
@ -88,7 +88,7 @@ const reactionEffects: IReactionEffect[] = [
}
if (lead.evo_agent_accountid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($evo_agent_accountid: Uuid!) {
account(accountid: $evo_agent_accountid) {
@ -123,7 +123,7 @@ const reactionEffects: IReactionEffect[] = [
}
if (lead.evo_double_agent_accountid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($evo_double_agent_accountid: Uuid!) {
account(accountid: $evo_double_agent_accountid) {
@ -158,7 +158,7 @@ const reactionEffects: IReactionEffect[] = [
}
if (lead.evo_broker_accountid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($evo_broker_accountid: Uuid!) {
account(accountid: $evo_broker_accountid) {
@ -190,7 +190,7 @@ const reactionEffects: IReactionEffect[] = [
}
if (lead.evo_fin_department_accountid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($evo_fin_department_accountid: Uuid!) {
account(accountid: $evo_fin_department_accountid) {
@ -272,7 +272,7 @@ const reactionEffects: IReactionEffect[] = [
);
} else {
if (opportunity.parentaccountid)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($accountid: Uuid!) {
account(accountid: $accountid) {
@ -300,7 +300,7 @@ const reactionEffects: IReactionEffect[] = [
);
if (lead) {
if (lead.customerid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($customerid: Uuid!) {
account(accountid: $customerid) {
@ -467,7 +467,7 @@ const reactionEffects: IReactionEffect[] = [
);
if (indAgentId)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -528,7 +528,7 @@ const reactionEffects: IReactionEffect[] = [
);
if (doubleAgentId)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -587,7 +587,7 @@ const reactionEffects: IReactionEffect[] = [
Status.Default,
);
if (calcFinDepartmentId)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -647,7 +647,7 @@ const reactionEffects: IReactionEffect[] = [
);
if (calcBrokerId)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -1317,7 +1317,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.accountid === dealerId,
);
if (dealer) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $salonaccountid: Uuid!) {
account: salon_providers(
@ -1378,7 +1378,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.accountid === dealerPersonId,
);
if (dealerPerson && dealerPerson.evo_broker_accountid) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($accountid: Uuid!) {
account(accountid: $accountid) {
@ -1427,7 +1427,7 @@ const reactionEffects: IReactionEffect[] = [
Status.Default,
);
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -1486,7 +1486,7 @@ const reactionEffects: IReactionEffect[] = [
Status.Default,
);
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -1720,7 +1720,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.evo_brandid === brandId,
);
if (brand) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_brandid: Uuid) {
evo_model: evo_models(
@ -1773,7 +1773,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.evo_modelid === modelId,
);
if (model) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_modelid: Uuid) {
evo_equipment: evo_equipments(
@ -2849,7 +2849,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.accountid === supplierId,
);
if (supplier && supplier.evo_fin_department_accountid)
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($accountid: Uuid!) {
account(accountid: $accountid) {
@ -2882,7 +2882,7 @@ const reactionEffects: IReactionEffect[] = [
calculationStore.setOptions('selectAgent', []);
calculationStore.setValue('agent', null);
if (channelId === 100000002) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query(
$statecode: Int
@ -2912,7 +2912,7 @@ const reactionEffects: IReactionEffect[] = [
});
} else {
if (supplierId) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $salonaccountid: Uuid!) {
account: salon_agents(
@ -2978,7 +2978,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.evo_gps_brandid === GPSBrandId,
);
if (gpsBrand) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_gps_brandid: Uuid) {
evo_gps_model: evo_gps_models(
@ -3030,7 +3030,7 @@ const reactionEffects: IReactionEffect[] = [
x => x.evo_regionid === regionRegistrationId,
);
if (regionRegistration) {
CalculationService.crmgqlquery({
CrmService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_regionid: Uuid) {
evo_town: evo_towns(

View File

@ -1,5 +1,5 @@
import { TElements } from '../types/Calculation/Store/elements';
import { IBaseOption } from '../types/Calculation/Store/options';
import { TElements } from 'core/types/Calculation/Store/elements';
import { IBaseOption } from 'core/types/Calculation/Store/options';
const initialOptions: TElements<IBaseOption[]> = {
selectChannel: [