diff --git a/src/client/Containers/Calculation/Results/resultsList.ts b/src/client/Containers/Calculation/Results/resultsList.ts index 40ab5a7..2b87687 100644 --- a/src/client/Containers/Calculation/Results/resultsList.ts +++ b/src/client/Containers/Calculation/Results/resultsList.ts @@ -3,7 +3,7 @@ import Label from 'client/Elements/Label'; import Select from 'client/Elements/Select'; import Switch from 'client/Elements/Switch'; import { IGroup } from 'core/types/Calculation/components'; -import { ElementType } from 'core/types/elements'; +import { ElementType } from 'core/types/Calculation/Store/elements'; const resultsList: IGroup[] = [ { diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index e35841d..3cd7a72 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -15,7 +15,7 @@ import { validatePhone, } from 'client/tools/validate'; import { ISections } from 'core/types/Calculation/components'; -import { ElementType } from 'core/types/elements'; +import { ElementType } from 'core/types/Calculation/Store/elements'; const sections: ISections[] = [ { diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index 710e962..0add888 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -17,37 +17,27 @@ const Calculation = () => { const { calculationStore } = useStores(); useEffect(() => { Promise.all([ - CalculationService.getInitialOptions({ + CalculationService.getEntitiesOptions({ elementsList: initialOptionsMap, }), CalculationService.getStaticData({ staticEntitiesList, }), CalculationService.getEntityOptions({ - entityName: 'lead', - fields: undefined, - where: undefined, - }), - CalculationService.getEntityOptions({ - entityName: 'opportunity', - }), - CalculationService.getEntityOptions({ - entityName: 'account', - where: { evo_account_type: 100000002, statecode: 0 }, + query: { + entityName: 'account', + where: { evo_account_type: 100000002, statecode: 0 }, + }, }), ]) .then( ([ - initialOptions, - staticEntities, - leadOptions, - opportunities, - insuranceCompanies, + { entitiesOptions: initialOptions }, + { staticEntities }, + { entityOptions: insuranceCompanies }, ]) => { calculationStore.applyOptions({ ...initialOptions }); - calculationStore.setStaticData(staticEntities); - calculationStore.applyOptions({ selectLead: leadOptions }); - calculationStore.applyOptions({ selectOpportunity: opportunities }); + calculationStore.applyStaticData(staticEntities); calculationStore.setTableColumns('tableInsurance')({ options: { insuranceCompany: insuranceCompanies }, }); diff --git a/src/client/Containers/Calculation/lib/buildElement.js b/src/client/Containers/Calculation/lib/buildElement.js index db0c3d3..6dad1a4 100644 --- a/src/client/Containers/Calculation/lib/buildElement.js +++ b/src/client/Containers/Calculation/lib/buildElement.js @@ -3,7 +3,7 @@ import { withStoreValue, withTableData, } from 'client/hocs/withStore'; -import { ElementType } from 'core/types/elements'; +import { ElementType } from 'core/types/Calculation/Store/elements'; export function buildElement({ type, diff --git a/src/client/hooks/Calculation/useValidation.ts b/src/client/hooks/Calculation/useValidation.ts index 9db490f..7e8478d 100644 --- a/src/client/hooks/Calculation/useValidation.ts +++ b/src/client/hooks/Calculation/useValidation.ts @@ -1,8 +1,12 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import { TableNames, TableValuesNames } from './../../../core/types/tables'; + import { ValidateStatus } from 'antd/lib/form/FormItem'; import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'core/constants/errorMessages'; -import { ElementsNames } from 'core/types/elements'; +import { ElementsNames } from 'core/types/Calculation/Store/elements'; +import { + TableNames, + TableValuesNames, +} from 'core/types/Calculation/Store/tables'; import { useEffect, useState } from 'react'; import { useStores } from '../useStores'; diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index 33a1e2f..781018e 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -1,19 +1,22 @@ -import { IOption } from 'core/types/Calculation/options'; import axios from 'axios'; import { - IGetEntity, - TGetEntityOptionsResponse, - TGetInitialOptions, - TGetInitialOptionsResponse, -} from 'core/types/Requests/Calculation'; + IGetEntitiesOptionsRequest, + IGetEntityOptionsRequest, +} from 'core/types/Calculation/Requests'; +import { + IGetEntitiesOptionsResponse, + IGetEntityOptionsResponse, +} from 'core/types/Calculation/Responses'; +import { IGetStaticEntitiesRequest } from './../../core/types/Calculation/Requests'; +import { IGetStaticEntitiesResponse } from './../../core/types/Calculation/Responses'; class CalculationService { - static getInitialOptions = ({ + static getEntitiesOptions = ({ elementsList, - }: TGetInitialOptions): Promise => + }: IGetEntitiesOptionsRequest): Promise => new Promise((resolve, reject) => { axios - .post('/api/calculation/getInitialOptions', { elementsList }) + .post('/api/calculation/getEntitiesOptions', { elementsList }) .then(res => { resolve(res.data); }) @@ -23,20 +26,13 @@ class CalculationService { }); static getEntityOptions = ({ - entityName, - fields, - where, - }: IGetEntity): Promise => + query, + }: IGetEntityOptionsRequest): Promise => new Promise((resolve, reject) => { axios - .post('/api/calculation/getEntityOptions', { - entityName, - fields, - where, - }) + .post('/api/calculation/getEntityOptions', { query }) .then(res => { - const { entityOptions } = res.data; - resolve(entityOptions); + resolve(res.data); }) .catch(err => { reject(err); @@ -45,17 +41,14 @@ class CalculationService { static getStaticData = ({ staticEntitiesList, - }: { - staticEntitiesList: IGetEntity[]; - }): Promise => + }: IGetStaticEntitiesRequest): Promise => new Promise((resolve, reject) => { axios .post('/api/calculation/getStaticEntities', { staticEntitiesList, }) .then(res => { - const { staticEntities } = res.data; - resolve(staticEntities); + resolve(res.data); }) .catch(err => { reject(err); diff --git a/src/client/stores/CalculationStore/Data/staticEntities.js b/src/client/stores/CalculationStore/Data/staticEntities.js index 06332bc..0ff477e 100644 --- a/src/client/stores/CalculationStore/Data/staticEntities.js +++ b/src/client/stores/CalculationStore/Data/staticEntities.js @@ -4,7 +4,7 @@ const staticDataAction = { getStaticData(dataName) { return this.staticData[dataName]; }, - setStaticData(data) { + applyStaticData(data) { this.staticData = { ...this.staticData, ...data }; }, }; diff --git a/src/client/stores/CalculationStore/Effects/action.ts b/src/client/stores/CalculationStore/Effects/action.ts index aede691..b54f7cb 100644 --- a/src/client/stores/CalculationStore/Effects/action.ts +++ b/src/client/stores/CalculationStore/Effects/action.ts @@ -1,10 +1,11 @@ import { openNotification } from 'client/Elements/Notification'; import CalculationStore from 'client/stores/CalculationStore'; -import { TAction } from 'core/types/effect'; -import { Status } from 'core/types/statuses'; +import { TAction } from 'core/types/Calculation/Store/effect'; const actions: TAction = { createLead: () => { + // TODO: block button for time + // TODO: collect errors const { contactClient, contact, @@ -146,6 +147,9 @@ const actions: TAction = { } }, calculate: () => { + // TODO: block button for time + // TODO: collect errors + const { rows } = CalculationStore.tables.tableInsurance; const kaskoRow = rows[1]; const DGORow = rows[2]; diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 542d282..10d8d72 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -1,4 +1,4 @@ -import { IAutorunEffect } from 'core/types/effect'; +import { IAutorunEffect } from 'core/types/Calculation/Store/effect'; const autorunEffects: IAutorunEffect[] = [ calculationStore => () => { diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 7689f46..ce33128 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -1,9 +1,9 @@ import { openNotification } from 'client/Elements/Notification'; import CalculationService from 'client/services/CalculationService'; import { shift, shiftRight } from 'core/tools/array'; -import { IReactionEffect } from 'core/types/effect'; +import { IReactionEffect } from 'core/types/Calculation/Store/effect'; import { Status } from 'core/types/statuses'; -import { ITableCell, TableProps } from 'core/types/tables'; +import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables'; import { toJS } from 'mobx'; import { calcPrice, calculatePerc, calculateRub } from './lib/tools'; @@ -24,10 +24,12 @@ const reactionEffects: IReactionEffect[] = [ if (lead) { CalculationService.getEntityOptions({ - entityName: 'opportunity', - where: { opportunityid: lead.evo_opportunityid || null }, + query: { + entityName: 'opportunity', + where: { opportunityid: lead.evo_opportunityid || null }, + }, }) - .then(opportunities => { + .then(({ entityOptions: opportunities }) => { if (opportunities) { calculationStore.setOptions('selectOpportunity', opportunities); calculationStore.setValue( @@ -41,12 +43,14 @@ const reactionEffects: IReactionEffect[] = [ }); CalculationService.getEntityOptions({ - entityName: 'quote', - where: { - evo_leadid: leadId || null, + query: { + entityName: 'quote', + where: { + evo_leadid: leadId || null, + }, }, }) - .then(quotes => { + .then(({ entityOptions: quotes }) => { calculationStore.setOptions('selectQuote', quotes); if (quotes.length === 0) calculationStore.setValue('quote', null); }) @@ -55,12 +59,14 @@ const reactionEffects: IReactionEffect[] = [ }); CalculationService.getEntityOptions({ - entityName: 'account', - where: { - accountid: lead.evo_agent_accountid || null, + query: { + entityName: 'account', + where: { + accountid: lead.evo_agent_accountid || null, + }, }, }) - .then(agents => { + .then(({ entityOptions: agents }) => { calculationStore.setOptions('selectIndAgent', agents); calculationStore.setValue( 'indAgent', @@ -72,12 +78,14 @@ const reactionEffects: IReactionEffect[] = [ }); CalculationService.getEntityOptions({ - entityName: 'account', - where: { - accountid: lead.evo_double_agent_accountid || null, + query: { + entityName: 'account', + where: { + accountid: lead.evo_double_agent_accountid || null, + }, }, }) - .then(doubleAgents => { + .then(({ entityOptions: doubleAgents }) => { calculationStore.setOptions('selectCalcDoubleAgent', doubleAgents); calculationStore.setValue( 'calcDoubleAgent', @@ -89,12 +97,14 @@ const reactionEffects: IReactionEffect[] = [ }); CalculationService.getEntityOptions({ - entityName: 'account', - where: { - accountid: lead.evo_broker_accountid || null, + query: { + entityName: 'account', + where: { + accountid: lead.evo_broker_accountid || null, + }, }, }) - .then(brokers => { + .then(({ entityOptions: brokers }) => { calculationStore.setOptions('selectCalcBroker', brokers); calculationStore.setValue( 'calcBroker', @@ -106,12 +116,14 @@ const reactionEffects: IReactionEffect[] = [ }); CalculationService.getEntityOptions({ - entityName: 'account', - where: { - accountid: lead.evo_fin_department_accountid || null, + query: { + entityName: 'account', + where: { + accountid: lead.evo_fin_department_accountid || null, + }, }, }) - .then(finDepartments => { + .then(({ entityOptions: finDepartments }) => { calculationStore.setOptions( 'selectCalcFinDepartment', finDepartments, @@ -176,9 +188,11 @@ const reactionEffects: IReactionEffect[] = [ ); } else { CalculationService.getEntityOptions({ - entityName: 'account', - where: { accountid: opportunity.evo_accountid }, - }).then(accounts => { + query: { + entityName: 'account', + where: { accountid: opportunity.evo_accountid }, + }, + }).then(({ entityOptions: accounts }) => { if ( accounts && accounts.length > 0 && @@ -198,9 +212,11 @@ const reactionEffects: IReactionEffect[] = [ if (lead) { if (lead.account) { CalculationService.getEntityOptions({ - entityName: 'account', - where: { accountid: lead.account }, - }).then(accounts => { + query: { + entityName: 'account', + where: { accountid: lead.account }, + }, + }).then(({ entityOptions: accounts }) => { if (accounts.length > 0) calculationStore.setValue( 'clientRisk', @@ -350,16 +366,18 @@ const reactionEffects: IReactionEffect[] = [ Status.Default, ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: indAgentId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: indAgentId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectIndAgentRewardCondition', reward_conditions, @@ -391,16 +409,18 @@ const reactionEffects: IReactionEffect[] = [ Status.Default, ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: doubleAgentId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: doubleAgentId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectCalcDoubleAgentRewardCondition', reward_conditions, @@ -432,16 +452,18 @@ const reactionEffects: IReactionEffect[] = [ Status.Default, ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: calcFinDepartmentId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: calcFinDepartmentId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectFinDepartmentRewardCondtion', reward_conditions, @@ -473,16 +495,18 @@ const reactionEffects: IReactionEffect[] = [ Status.Default, ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: calcBrokerId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: calcBrokerId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectCalcBrokerRewardCondition', reward_conditions, @@ -1092,12 +1116,14 @@ const reactionEffects: IReactionEffect[] = [ ); if (dealer && dealer.evo_broker_accountid) { CalculationService.getEntityOptions({ - entityName: 'account', - where: { - accountid: dealer.evo_broker_accountid, + query: { + entityName: 'account', + where: { + accountid: dealer.evo_broker_accountid, + }, }, }) - .then(brokers => { + .then(({ entityOptions: brokers }) => { if (brokers && brokers.length > 0) { calculationStore.setOptions('selectDealerPerson', brokers); calculationStore.setValue('dealerPerson', brokers[0].accountid); @@ -1131,13 +1157,15 @@ const reactionEffects: IReactionEffect[] = [ ); if (dealerPerson && dealerPerson.evo_broker_accountid) { CalculationService.getEntityOptions({ - entityName: 'account', - where: { - statecode: 0, - accountid: dealerPerson.evo_broker_accountid, + query: { + entityName: 'account', + where: { + statecode: 0, + accountid: dealerPerson.evo_broker_accountid, + }, }, }) - .then(brokers => { + .then(({ entityOptions: brokers }) => { if (brokers && brokers.length > 0) { calculationStore.setOptions('selectDealerBroker', brokers); calculationStore.setValue('dealerBroker', brokers[0].accountid); @@ -1176,16 +1204,18 @@ const reactionEffects: IReactionEffect[] = [ ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: dealerBrokerId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: dealerBrokerId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectDealerBrokerRewardСondition', reward_conditions, @@ -1217,16 +1247,18 @@ const reactionEffects: IReactionEffect[] = [ Status.Default, ); CalculationService.getEntityOptions({ - entityName: 'evo_reward_condition', - where: { - statecode: 0, - // TODO < > текущей даты - // evo_datefrom: new Date(), - // evo_dateto: new Date(), - evo_agent_accountid: dealerPersonId, + query: { + entityName: 'evo_reward_condition', + where: { + statecode: 0, + // TODO < > текущей даты + // evo_datefrom: new Date(), + // evo_dateto: new Date(), + evo_agent_accountid: dealerPersonId, + }, }, }) - .then(reward_conditions => { + .then(({ entityOptions: reward_conditions }) => { calculationStore.setOptions( 'selectDealerRewardСondition', reward_conditions, @@ -1424,12 +1456,14 @@ const reactionEffects: IReactionEffect[] = [ ); if (brand) { CalculationService.getEntityOptions({ - entityName: 'evo_model', - where: { - statecode: 0, - evo_brandid: brandId, + query: { + entityName: 'evo_model', + where: { + statecode: 0, + evo_brandid: brandId, + }, }, - }).then(models => { + }).then(({ entityOptions: models }) => { if (models && models.length > 0) { calculationStore.setStatus('selectModel', Status.Default); calculationStore.setOptions('selectModel', models); @@ -1457,12 +1491,14 @@ const reactionEffects: IReactionEffect[] = [ ); if (model) { CalculationService.getEntityOptions({ - entityName: 'evo_equipment', - where: { - statecode: 0, - evo_modelid: modelId, + query: { + entityName: 'evo_equipment', + where: { + statecode: 0, + evo_modelid: modelId, + }, }, - }).then(equipments => { + }).then(({ entityOptions: equipments }) => { if (equipments && equipments.length > 0) { calculationStore.setStatus('selectConfiguration', Status.Default); calculationStore.setOptions('selectConfiguration', equipments); @@ -1891,13 +1927,15 @@ const reactionEffects: IReactionEffect[] = [ if (quote.evo_recalc_limit && quote.evo_recalc_limit > 0) { if (quote.evo_statuscodeid) { CalculationService.getEntityOptions({ - entityName: 'evo_statuscode', - where: { - evo_statuscodeid: quote.evo_statuscodeid, - statecode: 0, + query: { + entityName: 'evo_statuscode', + where: { + evo_statuscodeid: quote.evo_statuscodeid, + statecode: 0, + }, }, }) - .then(evo_statuscodes => { + .then(({ entityOptions: evo_statuscodes }) => { if (evo_statuscodes && evo_statuscodes.length > 0) { const evo_statuscode = evo_statuscodes[0]; if (evo_statuscode.evo_id === '2.3') { diff --git a/src/client/stores/CalculationStore/Effects/when.ts b/src/client/stores/CalculationStore/Effects/when.ts index 9a7045b..ec6239f 100644 --- a/src/client/stores/CalculationStore/Effects/when.ts +++ b/src/client/stores/CalculationStore/Effects/when.ts @@ -1,4 +1,4 @@ -import { IWhenEffect } from 'core/types/effect'; +import { IWhenEffect } from 'core/types/Calculation/Store/effect'; const whenEffects: IWhenEffect[] = [ // calculationStore => ({ diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index e897979..30ace45 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -4,7 +4,7 @@ import { } from 'client/stores/CalculationStore/Data/modal'; import actionsEffects from 'client/stores/CalculationStore/Effects/action'; // import assignProperties from 'client/tools/assignProps'; -import { ICalculationStore } from 'core/types/stores'; +import { ICalculationStore } from 'core/types/Calculation/Store'; import { isEqual } from 'lodash'; import { autorun, makeAutoObservable, reaction, when } from 'mobx'; import CommonStore from '../CommonStore'; diff --git a/src/core/Data/initialOptionsMap.ts b/src/core/Data/initialOptionsMap.ts index 7b80228..badf41f 100644 --- a/src/core/Data/initialOptionsMap.ts +++ b/src/core/Data/initialOptionsMap.ts @@ -1,6 +1,14 @@ -import { TInitialElementsOptions } from 'core/types/Requests/Calculation'; +import { TElements } from 'core/types/Calculation/Store/elements'; +import { TGetEntities } from 'core/types/Entities/query'; + +const initialOptionMap: TElements = { + selectLead: { + entityName: 'lead', + fields: undefined, + where: undefined, + }, + selectOpportunity: { entityName: 'opportunity' }, -const initialOptionMap: TInitialElementsOptions = { selectSupplier: { entityName: 'account', where: { diff --git a/src/core/Data/propsMap.ts b/src/core/Data/propsMap.ts index d506033..c64538f 100644 --- a/src/core/Data/propsMap.ts +++ b/src/core/Data/propsMap.ts @@ -1,8 +1,7 @@ -import { EntityNames } from 'core/types/Entities/entityNames'; +import { IBaseOption } from 'core/types/Calculation/Store/options'; +import { TEntities } from './../types/Entities/entityNames'; -const propsMap: { - [entity in EntityNames]?: { name: string; value: string }; -} = { +const propsMap: TEntities = { account: { name: 'name', value: 'accountid', diff --git a/src/core/Data/staticEntitiesList.ts b/src/core/Data/staticEntitiesList.ts index 621c99d..e078657 100644 --- a/src/core/Data/staticEntitiesList.ts +++ b/src/core/Data/staticEntitiesList.ts @@ -1,6 +1,6 @@ -import { IGetEntity } from '../types/Requests/Calculation'; +import { TGetEntities } from '../types/Entities/query'; -const staticEntitiesList: IGetEntity[] = [ +const staticEntitiesList: TGetEntities[] = [ { entityName: 'evo_impairment_group', where: { @@ -9,8 +9,11 @@ const staticEntitiesList: IGetEntity[] = [ }, { entityName: 'evo_currencychange', - evo_coursedate: new Date(), - statecode: 0, + where: { + //TODO: Date without time + // evo_coursedate: new Date(), + statecode: 0, + }, }, ]; diff --git a/src/core/config/initialFilters.ts b/src/core/config/initialFilters.ts index 7f28b80..6b7dc45 100644 --- a/src/core/config/initialFilters.ts +++ b/src/core/config/initialFilters.ts @@ -1,5 +1,5 @@ -import { TElementFilter } from 'core/types/Calculation/filters'; -import { TElements } from 'core/types/elements'; +import { TElementFilter } from 'core/types/Calculation/Store/filters'; +import { TElements } from 'core/types/Calculation/Store/elements'; const initialFilters: TElements = {}; diff --git a/src/core/config/initialOptions.ts b/src/core/config/initialOptions.ts index 06d794f..1158555 100644 --- a/src/core/config/initialOptions.ts +++ b/src/core/config/initialOptions.ts @@ -1,5 +1,5 @@ -import { TElements } from 'core/types/elements'; -import { IBaseOption } from 'core/types/Calculation/options'; +import { TElements } from '../types/Calculation/Store/elements'; +import { IBaseOption } from '../types/Calculation/Store/options'; const initialOptions: TElements = { selectChannel: [ diff --git a/src/core/config/initialStatuses.ts b/src/core/config/initialStatuses.ts index 4eb2121..b3dcf5e 100644 --- a/src/core/config/initialStatuses.ts +++ b/src/core/config/initialStatuses.ts @@ -1,6 +1,7 @@ -import { Status, TStatuses } from '../types/statuses'; +import { Status } from 'core/types/statuses'; +import { TElements } from 'core/types/Calculation/Store/elements'; -const initialStatuses: TStatuses = { +const initialStatuses: TElements = { selectIndAgent: Status.Disabled, selectCalcBroker: Status.Disabled, selectCalcFinDepartment: Status.Disabled, diff --git a/src/core/config/initialTables/tableInsurance.ts b/src/core/config/initialTables/tableInsurance.ts index ef3e038..630f72c 100644 --- a/src/core/config/initialTables/tableInsurance.ts +++ b/src/core/config/initialTables/tableInsurance.ts @@ -1,6 +1,6 @@ import { openNotification } from 'client/Elements/Notification'; +import { ITable } from 'core/types/Calculation/Store/tables'; import { Status } from 'core/types/statuses'; -import { ITable } from 'core/types/tables'; const tableInsurance: ITable = { rows: [ diff --git a/src/core/config/initialTables/tablePayments.ts b/src/core/config/initialTables/tablePayments.ts index 4ff2069..9d09562 100644 --- a/src/core/config/initialTables/tablePayments.ts +++ b/src/core/config/initialTables/tablePayments.ts @@ -1,4 +1,4 @@ -import { ITable } from 'core/types/tables'; +import { ITable } from 'core/types/Calculation/Store/tables'; import { toJS } from 'mobx'; const tablePayments: ITable = { diff --git a/src/core/config/initialValues.ts b/src/core/config/initialValues.ts index 4de1d16..8ba6299 100644 --- a/src/core/config/initialValues.ts +++ b/src/core/config/initialValues.ts @@ -1,4 +1,5 @@ -import { TValue, TValues } from 'core/types/values'; +import { TValues, TValue } from 'core/types/Calculation/Store/values'; + const initialValues: TValues = { recalcWithRevision: false, contactGender: 100000000, diff --git a/src/core/fakeData/entityFakes.ts b/src/core/fakeData/entityFakes.ts index 8c19481..3c5f1af 100644 --- a/src/core/fakeData/entityFakes.ts +++ b/src/core/fakeData/entityFakes.ts @@ -1,8 +1,8 @@ -import { IOption } from 'core/types/Calculation/options'; -import { EntityNames } from 'core/types/Entities/entityNames'; - +import { IOption } from 'core/types/Calculation/Store/options'; +import { TEntities } from 'core/types/Entities/entityNames'; import faker from 'faker'; + /** * Fake Consts */ @@ -102,9 +102,7 @@ const EVO_STATUSCODE_ID = Array.from({ length: 5 }, () => faker.random.uuid()); * Fake Consts */ -const entityFakeData: { - [entity in EntityNames]?: IOption[]; -} = { +const entityFakeData: TEntities = { account: [ { accountid: ACCOUNT_1_ID, @@ -653,7 +651,7 @@ const entityFakeData: { evo_name: 'Доллар на сегодня', evo_ref_transactioncurrency: TRANSACTION_CURRENTCY_2_ID, evo_currencychange: 100, - evo_coursedate: new Date(), + // evo_coursedate: new Date(), statecode: 0, }, { @@ -661,7 +659,7 @@ const entityFakeData: { evo_name: 'Евро на сегодня', evo_ref_transactioncurrency: TRANSACTION_CURRENTCY_3_ID, evo_currencychange: 200, - evo_coursedate: new Date(), + // evo_coursedate: new Date(), statecode: 0, }, ], diff --git a/src/core/index.ts b/src/core/index.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/src/core/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/src/core/types/Calculation/Requests.ts b/src/core/types/Calculation/Requests.ts new file mode 100644 index 0000000..783251a --- /dev/null +++ b/src/core/types/Calculation/Requests.ts @@ -0,0 +1,14 @@ +import { TGetEntities } from '../Entities/query'; +import { TElements } from './../Calculation/Store/elements'; + +export interface IGetEntitiesOptionsRequest { + elementsList: TElements; +} + +export interface IGetEntityOptionsRequest { + query: TGetEntities; +} + +export interface IGetStaticEntitiesRequest { + staticEntitiesList: TGetEntities[]; +} diff --git a/src/core/types/Calculation/Responses.ts b/src/core/types/Calculation/Responses.ts new file mode 100644 index 0000000..882deab --- /dev/null +++ b/src/core/types/Calculation/Responses.ts @@ -0,0 +1,15 @@ +import { TEntities } from './../Entities/entityNames'; +import { TElements } from './Store/elements'; +import { IOption } from './Store/options'; + +export interface IGetEntitiesOptionsResponse { + entitiesOptions: TElements; +} + +export interface IGetEntityOptionsResponse { + entityOptions: IOption[]; +} + +export interface IGetStaticEntitiesResponse { + staticEntities: TEntities; +} diff --git a/src/core/types/effect.ts b/src/core/types/Calculation/Store/effect.ts similarity index 94% rename from src/core/types/effect.ts rename to src/core/types/Calculation/Store/effect.ts index 2120094..a7fe110 100644 --- a/src/core/types/effect.ts +++ b/src/core/types/Calculation/Store/effect.ts @@ -1,6 +1,6 @@ import CommonStore from 'client/stores/CommonStore'; import { IReactionOptions, IReactionPublic, Lambda } from 'mobx'; -import { ICalculationStore } from './stores'; +import { ICalculationStore } from './'; type TCommonStore = typeof CommonStore; diff --git a/src/core/types/elements.ts b/src/core/types/Calculation/Store/elements.ts similarity index 100% rename from src/core/types/elements.ts rename to src/core/types/Calculation/Store/elements.ts diff --git a/src/core/types/Calculation/filters.ts b/src/core/types/Calculation/Store/filters.ts similarity index 52% rename from src/core/types/Calculation/filters.ts rename to src/core/types/Calculation/Store/filters.ts index 245fac9..fa6c53f 100644 --- a/src/core/types/Calculation/filters.ts +++ b/src/core/types/Calculation/Store/filters.ts @@ -1,3 +1,3 @@ -import { IOption } from 'core/types/Calculation/options'; +import { IOption } from './options'; export type TElementFilter = (options: IOption[]) => IOption[]; diff --git a/src/core/types/stores.ts b/src/core/types/Calculation/Store/index.ts similarity index 86% rename from src/core/types/stores.ts rename to src/core/types/Calculation/Store/index.ts index 730f2bb..6425c0a 100644 --- a/src/core/types/stores.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -1,22 +1,17 @@ -import { TElementFilter } from 'core/types/Calculation/filters'; -import { IOption } from 'core/types/Calculation/options'; -import { - ITableCell, - TableNames, - TableProps, - TCellCallback, -} from 'core/types/tables'; +import { TElementFilter } from './filters'; +import { IOption } from './options'; +import { ITableCell, TableNames, TableProps, TCellCallback } from './tables'; import { ElementsNames, TElements } from './elements'; -import { EntityNames } from './Entities/entityNames'; +import { EntityNames } from '../../Entities/entityNames'; import { StaticDataNames, TStaticData } from './staticData'; -import { Status } from './statuses'; +import { Status } from '../../statuses'; import { StoreTables } from './tables'; import { TValue, TValues, ValuesNames } from './values'; interface ICalculationValues { staticData: TStaticData; getStaticData: (dataName: StaticDataNames | EntityNames) => IOption[]; - setStaticData: (data: TStaticData) => void; + applyStaticData: (data: TStaticData) => void; options: TElements; getOptions: (elementName: ElementsNames) => IOption[]; diff --git a/src/core/types/Calculation/options.ts b/src/core/types/Calculation/Store/options.ts similarity index 80% rename from src/core/types/Calculation/options.ts rename to src/core/types/Calculation/Store/options.ts index a1dbdf9..a3018f0 100644 --- a/src/core/types/Calculation/options.ts +++ b/src/core/types/Calculation/Store/options.ts @@ -1,4 +1,4 @@ -import { TEntity } from 'core/types/Entities'; +import { TEntity } from '../../Entities'; export type IBaseOption = { /** diff --git a/src/core/types/staticData.ts b/src/core/types/Calculation/Store/staticData.ts similarity index 59% rename from src/core/types/staticData.ts rename to src/core/types/Calculation/Store/staticData.ts index 75630f1..f981dd3 100644 --- a/src/core/types/staticData.ts +++ b/src/core/types/Calculation/Store/staticData.ts @@ -1,5 +1,5 @@ -import { EntityNames } from 'core/types/Entities/entityNames'; -import { IOption } from './Calculation/options'; +import { EntityNames } from '../../Entities/entityNames'; +import { IOption } from '../../Calculation/Store/options'; import { TValue } from './values'; export type StaticDataNames = ''; diff --git a/src/core/types/tables.ts b/src/core/types/Calculation/Store/tables.ts similarity index 77% rename from src/core/types/tables.ts rename to src/core/types/Calculation/Store/tables.ts index 526fb0c..a7060b6 100644 --- a/src/core/types/tables.ts +++ b/src/core/types/Calculation/Store/tables.ts @@ -1,7 +1,7 @@ -import { ICalculationStore } from 'core/types/stores'; -import { TElementFilter } from 'core/types/Calculation/filters'; -import { IOption } from 'core/types/Calculation/options'; -import { Status } from './statuses'; +import { ICalculationStore } from './'; +import { TElementFilter } from './filters'; +import { IOption } from './options'; +import { Status } from '../../statuses'; export type TableNames = 'tableInsurance' | 'tablePayments'; export type TableValuesNames = diff --git a/src/core/types/values.ts b/src/core/types/Calculation/Store/values.ts similarity index 100% rename from src/core/types/values.ts rename to src/core/types/Calculation/Store/values.ts diff --git a/src/core/types/Calculation/components.ts b/src/core/types/Calculation/components.ts index dfe279d..6f22ac6 100644 --- a/src/core/types/Calculation/components.ts +++ b/src/core/types/Calculation/components.ts @@ -1,7 +1,7 @@ -import { TableNames, TableValuesNames } from './../tables'; -import { ActionsNames } from 'core/types/effect'; -import { ElementsNames, ElementType } from 'core/types/elements'; -import { ComputedValuesNames, ValuesNames } from 'core/types/values'; +import { TableNames, TableValuesNames } from './Store/tables'; +import { ActionsNames } from './Store/effect'; +import { ElementsNames, ElementType } from './Store/elements'; +import { ComputedValuesNames, ValuesNames } from './Store/values'; interface IElement { type?: ElementType; diff --git a/src/core/types/Entities/entityNames.ts b/src/core/types/Entities/entityNames.ts index e4d754e..b83e7a5 100644 --- a/src/core/types/Entities/entityNames.ts +++ b/src/core/types/Entities/entityNames.ts @@ -22,3 +22,7 @@ export type EntityNames = | 'evo_impairment_group' | 'evo_currencychange' | 'evo_statuscode'; + +export type TEntities = { + [entityName in EntityNames]?: T; +}; diff --git a/src/core/types/Entities/index.ts b/src/core/types/Entities/index.ts index b199868..18040d5 100644 --- a/src/core/types/Entities/index.ts +++ b/src/core/types/Entities/index.ts @@ -1,4 +1,4 @@ -import { IBaseOption } from 'core/types/Calculation/options'; +import { IBaseOption } from '../Calculation/Store/options'; export interface IAccount extends IBaseOption { accountid?: string; diff --git a/src/core/types/Entities/query.ts b/src/core/types/Entities/query.ts new file mode 100644 index 0000000..1fc5c2e --- /dev/null +++ b/src/core/types/Entities/query.ts @@ -0,0 +1,8 @@ +import { EntityNames } from './entityNames'; + +export type TGetEntities = { + entityName: EntityNames; + fields?: string[]; + where?: { [prop: string]: any }; + whereIn?: { [prop: string]: any }; +}; diff --git a/src/core/types/Requests/Calculation.ts b/src/core/types/Requests/Calculation.ts deleted file mode 100644 index fa1b557..0000000 --- a/src/core/types/Requests/Calculation.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { IOption } from 'core/types/Calculation/options'; -import { EntityNames } from 'core/types/Entities/entityNames'; -import { ElementsNames } from 'core/types/elements'; - -export type TInitialElementsOptions = { - [elementName in ElementsNames]?: IGetEntity; -}; - -export type TGetInitialOptions = { - elementsList: TInitialElementsOptions; -}; - -export type TGetInitialOptionsResponse = { - [elementName in ElementsNames]?: IOption[]; -}; - -export interface IGetEntity { - entityName: EntityNames; - fields?: string[]; - where?: { [prop: string]: any }; - whereIn?: { [prop: string]: any }; - [prop: string]: any; -} - -export type TGetEntityOptionsResponse = IOption[]; diff --git a/src/core/types/statuses.ts b/src/core/types/statuses.ts index c1a65b2..936c228 100644 --- a/src/core/types/statuses.ts +++ b/src/core/types/statuses.ts @@ -1,5 +1,3 @@ -import { ElementsNames } from 'core/types/elements'; - export enum Status { Default, Disabled, @@ -7,7 +5,3 @@ export enum Status { Loading, Readonly, } - -export type TStatuses = { - [elementName in ElementsNames]?: any; -}; diff --git a/src/server/controllers/CalculationController.ts b/src/server/controllers/CalculationController.ts index 49702ab..c53be90 100644 --- a/src/server/controllers/CalculationController.ts +++ b/src/server/controllers/CalculationController.ts @@ -1,20 +1,29 @@ -import { objectToOption } from '../../core/tools/data'; -import { - IGetEntity, - TGetInitialOptions, - TGetInitialOptionsResponse, -} from 'core/types/Requests/Calculation'; import { Request, Response } from 'express'; import entityFakeData from '../../core/fakeData/entityFakes'; -import { EntityNames } from 'core/types/Entities/entityNames'; -import { IOption } from 'core/types/Calculation/options'; -import { ElementsNames } from 'core/types/elements'; +import { objectToOption } from '../../core/tools/data'; +import { + IGetEntityOptionsRequest, + IGetEntitiesOptionsRequest, + IGetStaticEntitiesRequest, +} from './../../core/types/Calculation/Requests'; +import { + IGetEntityOptionsResponse, + IGetEntitiesOptionsResponse, + IGetStaticEntitiesResponse, +} from './../../core/types/Calculation/Responses'; +import { IOption } from './../../core/types/Calculation/Store/options'; +import { TGetEntities } from './../../core/types/Entities/query'; -function _getFakeEntities(entityName, fields?, where?, wherein?): IOption[] { +function _getFakeEntities({ + entityName, + fields, + where, + whereIn, +}: TGetEntities): IOption[] { let entities = entityFakeData[entityName]; - let totalWhere = Object.assign({}, where, wherein); + let totalWhere = Object.assign({}, where, whereIn); - if (entities) + if (entities !== undefined) { if (Object.keys(totalWhere).length > 0) entities = entities.filter(entity => { for (let w in totalWhere) { @@ -24,41 +33,41 @@ function _getFakeEntities(entityName, fields?, where?, wherein?): IOption[] { } return true; }); - return entities; + return entities; + } + return []; } //TODO: move logic from controller to service class CalculationController { - static getInitialOptions = async ( + static getEntitiesOptions = async ( req: Request, - res: Response, - ): Promise => { - const { elementsList }: { elementsList: TGetInitialOptions } = req.body; - let options = {}; + res: Response, + ): Promise => { + const { elementsList }: IGetEntitiesOptionsRequest = req.body; + + let entitiesOptions = {}; Object.keys(elementsList).forEach(elementName => { - const element: IGetEntity = elementsList[elementName]; - let opts = _getFakeEntities( - element.entityName, - element.fields, - element.where, - element.whereIn, + const element: TGetEntities = elementsList[elementName]; + let entityOptions = _getFakeEntities({ ...element }); + entityOptions = entityOptions.map(opt => + objectToOption(opt, element.entityName), ); - opts = opts.map(opt => objectToOption(opt, element.entityName)); - options[elementName] = opts; + entitiesOptions[elementName] = entityOptions; }); - res.send(options); + + res.send({ entitiesOptions }); }; static getEntityOptions = async ( req: Request, - res: Response, - ): Promise => { - // TODO request to Core - const { entityName, fields, where }: IGetEntity = req.body; + res: Response, + ): Promise => { + const { query }: IGetEntityOptionsRequest = req.body; - let entityOptions = _getFakeEntities(entityName, fields, where); + let entityOptions = _getFakeEntities(query); entityOptions = entityOptions.map(entityOption => - objectToOption(entityOption, entityName), + objectToOption(entityOption, query.entityName), ); res.send({ @@ -68,22 +77,13 @@ class CalculationController { static getStaticEntities = async ( req: Request, - res: Response, - ): Promise => { - const { - staticEntitiesList, - }: { staticEntitiesList: IGetEntity[] } = req.body; + res: Response, + ): Promise => { + const { staticEntitiesList }: IGetStaticEntitiesRequest = req.body; let staticEntities = {}; staticEntitiesList.forEach(entityQuery => { - const entityList = _getFakeEntities( - entityQuery.entityName, - entityQuery.fields, - entityQuery.where, - entityQuery.whereIn, - ); - if (entityList) { - staticEntities[entityQuery.entityName] = entityList; - } + const entityOptions = _getFakeEntities({ ...entityQuery }); + staticEntities[entityQuery.entityName] = entityOptions; }); res.send({ staticEntities, diff --git a/src/server/routes/calculation.ts b/src/server/routes/calculation.ts index d6ce261..f92d7b7 100644 --- a/src/server/routes/calculation.ts +++ b/src/server/routes/calculation.ts @@ -3,7 +3,7 @@ import { Router } from 'express'; const router = Router(); -router.post('/getInitialOptions', CalculationController.getInitialOptions); +router.post('/getEntitiesOptions', CalculationController.getEntitiesOptions); router.post('/getEntityOptions', CalculationController.getEntityOptions); router.post('/getStaticEntities', CalculationController.getStaticEntities);