From b967c7650168f5c40bce72c03b9be2a63ed9dd1f Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 13 Jul 2021 14:43:39 +0300 Subject: [PATCH] elt fixes --- .../Containers/Calculation/lib/fetchData/index.js | 6 +++++- .../Effects/reactions/eltReactions.ts | 11 ++++++++--- .../Effects/reactions/loadKpReaction/index.ts | 15 ++++++--------- .../stores/CalculationStore/subStores/eltStore.ts | 9 +++++---- src/core/types/Calculation/Store/process.ts | 1 + 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/client/Containers/Calculation/lib/fetchData/index.js b/src/client/Containers/Calculation/lib/fetchData/index.js index d2aa985..fe75bff 100644 --- a/src/client/Containers/Calculation/lib/fetchData/index.js +++ b/src/client/Containers/Calculation/lib/fetchData/index.js @@ -1,6 +1,7 @@ import CalculationStore from 'client/stores/CalculationStore'; import UserStore from 'client/stores/UserStore'; import CrmService from 'core/services/CrmService'; +import { Process } from 'core/types/Calculation/Store/process'; import getUser from './getUser'; import insuranceQuery from './queries/insuranceQuery'; import optionsQuery from './queries/optionsQuery'; @@ -12,7 +13,8 @@ export default () => new Promise(async (resolve, reject) => { await getUser(); const domainname = UserStore.getDomainName(); - + const { calculationProcess } = CalculationStore.stores; + calculationProcess.addProcess(Process.Init); Promise.all([ CrmService.crmgqlquery({ ...initialOwnerQuery, @@ -79,6 +81,8 @@ export default () => ); } + calculationProcess.deleteProcess(Process.Init); + resolve(); }, ) diff --git a/src/client/stores/CalculationStore/Effects/reactions/eltReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/eltReactions.ts index 88428d6..1251e67 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/eltReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/eltReactions.ts @@ -36,20 +36,22 @@ const eltReactions: IReactionEffect[] = [ ) => ({ expression: () => { return calculationStore.getValues( - //@ts-ignore (resetFields as ElementsNames[]).map(getValueName), ); }, effect: () => { cancelRequests(insType); + if ( + calculationProcess.hasProcess(Process.Init) || calculationProcess.hasProcess(Process.ELT) || calculationProcess.hasProcess(Process.LoadKp) ) { return; } + const { ELTStore } = calculationStore.stores; - if (ELTStore[insType].isReseted() === true) { + if (ELTStore[insType]?.isReseted()) { return; } message.warn({ content: RESET_MESSAGES[insType] }); @@ -75,14 +77,17 @@ const eltReactions: IReactionEffect[] = [ }, effect: () => { cancelRequests(insType); + if ( + calculationProcess.hasProcess(Process.Init) || calculationProcess.hasProcess(Process.ELT) || calculationProcess.hasProcess(Process.LoadKp) ) { return; } + const { ELTStore } = calculationStore.stores; - if (ELTStore[insType].isReseted() === true) { + if (ELTStore[insType]?.isReseted()) { return; } message.warn({ content: RESET_MESSAGES[insType] }); diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index d972e15..b0bd448 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -13,7 +13,7 @@ import { Process } from 'core/types/Calculation/Store/process'; import { ValuesNames } from 'core/types/Calculation/Store/values'; import { IEvoGraph } from 'core/types/Entities/crmEntities'; import { ElementStatus } from 'core/types/statuses'; -import { get, isNil } from 'lodash'; +import { get, isEqual, isNil } from 'lodash'; import NIL from 'uuid/dist/nil'; import { getKpPropName } from './mapKpToValues'; import { mainOptionsQuery, secondaryOptionsQuery } from './optionsQuery'; @@ -498,7 +498,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ x => x.accountid === quote.evo_kasko_accountid, ); - if (kaskoIndex !== undefined) { + if (kaskoIndex >= 0) { const mapQuoteToELTKasko = { key: 'evo_kasko_accountid', accountid: 'evo_kasko_accountid', @@ -530,7 +530,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ const osagoIndex = ELTStore.osago.list.findIndex( x => x.accountid === quote.evo_osago_accountid, ); - if (osagoIndex !== undefined) { + if (osagoIndex >= 0) { const mapQuoteToELTOsago = { key: 'evo_osago_accountid', accountid: 'evo_osago_accountid', @@ -545,14 +545,11 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ if (!isNil(quoteValue)) row[rowFieldName] = quoteValue; }); - if (quote.evo_id_elt_osago) { - row['evo_id_elt_osago'] = parseInt(quote.evo_id_elt_osago); + if (row['numCalc']) { + row['numCalc'] = parseInt(row['numCalc']); } - if ( - Object.keys(mapQuoteToELTOsago).length + 1 === - Object.keys(row).length - ) { + if (isEqual(Object.keys(row), Object.keys(mapQuoteToELTOsago))) { ELTStore.addToCompanyRes('osago', osagoIndex, row); ELTStore.osago.setKey(quote.evo_osago_accountid); } diff --git a/src/client/stores/CalculationStore/subStores/eltStore.ts b/src/client/stores/CalculationStore/subStores/eltStore.ts index 883fab5..54b8b0e 100644 --- a/src/client/stores/CalculationStore/subStores/eltStore.ts +++ b/src/client/stores/CalculationStore/subStores/eltStore.ts @@ -1,6 +1,7 @@ // @ts-nocheck import { initFields } from 'client/Components/Calculation/ELT/Content/lib/resetIns'; -import { makeAutoObservable } from 'mobx'; +import { isEqual } from 'lodash'; +import { makeAutoObservable, toJS } from 'mobx'; const ELTStore = makeAutoObservable( Object.assign( @@ -8,8 +9,8 @@ const ELTStore = makeAutoObservable( ...['osago', 'kasko'].map(x => ({ [x]: { isReseted() { - return this.list.every( - x => Object.keys(x).length === initFields.length, + return this.list.every(x => + isEqual(Object.keys(toJS(x)), initFields), ); }, reset(list) { @@ -34,7 +35,7 @@ const ELTStore = makeAutoObservable( }, addToCompanyRes(insType, index, res) { const companyData = this[insType].list[index]; - this[insType].list[index] = { ...companyData, ...res }; + this[insType].list[index] = Object.assign(companyData, res); }, }, ), diff --git a/src/core/types/Calculation/Store/process.ts b/src/core/types/Calculation/Store/process.ts index 25f33eb..6003fb0 100644 --- a/src/core/types/Calculation/Store/process.ts +++ b/src/core/types/Calculation/Store/process.ts @@ -1,4 +1,5 @@ export enum Process { + Init, LoadKp, RecalcWithoutRevision, ELT,