refactor: types
This commit is contained in:
parent
1a6e28614c
commit
f682141a76
@ -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[] = [
|
||||
{
|
||||
|
||||
@ -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[] = [
|
||||
{
|
||||
|
||||
@ -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 },
|
||||
});
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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<TGetInitialOptionsResponse> =>
|
||||
}: IGetEntitiesOptionsRequest): Promise<IGetEntitiesOptionsResponse> =>
|
||||
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<TGetEntityOptionsResponse> =>
|
||||
query,
|
||||
}: IGetEntityOptionsRequest): Promise<IGetEntityOptionsResponse> =>
|
||||
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<IOption[]> =>
|
||||
}: IGetStaticEntitiesRequest): Promise<IGetStaticEntitiesResponse> =>
|
||||
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);
|
||||
|
||||
@ -4,7 +4,7 @@ const staticDataAction = {
|
||||
getStaticData(dataName) {
|
||||
return this.staticData[dataName];
|
||||
},
|
||||
setStaticData(data) {
|
||||
applyStaticData(data) {
|
||||
this.staticData = { ...this.staticData, ...data };
|
||||
},
|
||||
};
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { IAutorunEffect } from 'core/types/effect';
|
||||
import { IAutorunEffect } from 'core/types/Calculation/Store/effect';
|
||||
|
||||
const autorunEffects: IAutorunEffect[] = [
|
||||
calculationStore => () => {
|
||||
|
||||
@ -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') {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { IWhenEffect } from 'core/types/effect';
|
||||
import { IWhenEffect } from 'core/types/Calculation/Store/effect';
|
||||
|
||||
const whenEffects: IWhenEffect[] = [
|
||||
// calculationStore => ({
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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<TGetEntities> = {
|
||||
selectLead: {
|
||||
entityName: 'lead',
|
||||
fields: undefined,
|
||||
where: undefined,
|
||||
},
|
||||
selectOpportunity: { entityName: 'opportunity' },
|
||||
|
||||
const initialOptionMap: TInitialElementsOptions = {
|
||||
selectSupplier: {
|
||||
entityName: 'account',
|
||||
where: {
|
||||
|
||||
@ -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<IBaseOption> = {
|
||||
account: {
|
||||
name: 'name',
|
||||
value: 'accountid',
|
||||
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -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<TElementFilter> = {};
|
||||
|
||||
|
||||
@ -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<IBaseOption[]> = {
|
||||
selectChannel: [
|
||||
|
||||
@ -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<Status> = {
|
||||
selectIndAgent: Status.Disabled,
|
||||
selectCalcBroker: Status.Disabled,
|
||||
selectCalcFinDepartment: Status.Disabled,
|
||||
|
||||
@ -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: [
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { TValue, TValues } from 'core/types/values';
|
||||
import { TValues, TValue } from 'core/types/Calculation/Store/values';
|
||||
|
||||
const initialValues: TValues<TValue> = {
|
||||
recalcWithRevision: false,
|
||||
contactGender: 100000000,
|
||||
|
||||
@ -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<IOption[]> = {
|
||||
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,
|
||||
},
|
||||
],
|
||||
|
||||
@ -1 +0,0 @@
|
||||
export {};
|
||||
14
src/core/types/Calculation/Requests.ts
Normal file
14
src/core/types/Calculation/Requests.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { TGetEntities } from '../Entities/query';
|
||||
import { TElements } from './../Calculation/Store/elements';
|
||||
|
||||
export interface IGetEntitiesOptionsRequest {
|
||||
elementsList: TElements<TGetEntities>;
|
||||
}
|
||||
|
||||
export interface IGetEntityOptionsRequest {
|
||||
query: TGetEntities;
|
||||
}
|
||||
|
||||
export interface IGetStaticEntitiesRequest {
|
||||
staticEntitiesList: TGetEntities[];
|
||||
}
|
||||
15
src/core/types/Calculation/Responses.ts
Normal file
15
src/core/types/Calculation/Responses.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { TEntities } from './../Entities/entityNames';
|
||||
import { TElements } from './Store/elements';
|
||||
import { IOption } from './Store/options';
|
||||
|
||||
export interface IGetEntitiesOptionsResponse {
|
||||
entitiesOptions: TElements<IOption[]>;
|
||||
}
|
||||
|
||||
export interface IGetEntityOptionsResponse {
|
||||
entityOptions: IOption[];
|
||||
}
|
||||
|
||||
export interface IGetStaticEntitiesResponse {
|
||||
staticEntities: TEntities<IOption[]>;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
import { IOption } from 'core/types/Calculation/options';
|
||||
import { IOption } from './options';
|
||||
|
||||
export type TElementFilter = (options: IOption[]) => IOption[];
|
||||
@ -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<IOption[]>;
|
||||
getOptions: (elementName: ElementsNames) => IOption[];
|
||||
@ -1,4 +1,4 @@
|
||||
import { TEntity } from 'core/types/Entities';
|
||||
import { TEntity } from '../../Entities';
|
||||
|
||||
export type IBaseOption = {
|
||||
/**
|
||||
@ -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 = '';
|
||||
@ -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 =
|
||||
@ -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;
|
||||
|
||||
@ -22,3 +22,7 @@ export type EntityNames =
|
||||
| 'evo_impairment_group'
|
||||
| 'evo_currencychange'
|
||||
| 'evo_statuscode';
|
||||
|
||||
export type TEntities<T> = {
|
||||
[entityName in EntityNames]?: T;
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { IBaseOption } from 'core/types/Calculation/options';
|
||||
import { IBaseOption } from '../Calculation/Store/options';
|
||||
|
||||
export interface IAccount extends IBaseOption {
|
||||
accountid?: string;
|
||||
|
||||
8
src/core/types/Entities/query.ts
Normal file
8
src/core/types/Entities/query.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { EntityNames } from './entityNames';
|
||||
|
||||
export type TGetEntities = {
|
||||
entityName: EntityNames;
|
||||
fields?: string[];
|
||||
where?: { [prop: string]: any };
|
||||
whereIn?: { [prop: string]: any };
|
||||
};
|
||||
@ -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[];
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -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<any> => {
|
||||
const { elementsList }: { elementsList: TGetInitialOptions } = req.body;
|
||||
let options = {};
|
||||
res: Response<IGetEntitiesOptionsResponse>,
|
||||
): Promise<void> => {
|
||||
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<any> => {
|
||||
// TODO request to Core
|
||||
const { entityName, fields, where }: IGetEntity = req.body;
|
||||
res: Response<IGetEntityOptionsResponse>,
|
||||
): Promise<void> => {
|
||||
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<any> => {
|
||||
const {
|
||||
staticEntitiesList,
|
||||
}: { staticEntitiesList: IGetEntity[] } = req.body;
|
||||
res: Response<IGetStaticEntitiesResponse>,
|
||||
): Promise<void> => {
|
||||
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,
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user