From 26130621f23c9177ec2cd9bdb20cdd24c1a400e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A7=D0=B8=D0=BA=D0=B0=D0=BB=D0=BA=D0=B8=D0=BD?= Date: Wed, 11 Nov 2020 16:49:34 +0300 Subject: [PATCH] remove unnecessary union --- src/client/services/CalculationService.ts | 12 +--- .../CalculationStore/Effects/reaction.ts | 55 ++++++++++--------- src/core/types/Calculation/Requests.ts | 7 +-- src/core/types/Entities/crmEntities.ts | 2 +- src/core/types/Entities/query.ts | 4 +- 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index b8211fc..f712018 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -10,11 +10,7 @@ import { import { IGetEntitiesResponse } from 'core/types/Calculation/Responses'; import { IBaseOption } from 'core/types/Calculation/Store/options'; import { TCRMEntity } from 'core/types/Entities/crmEntities'; -import { - CRMEntityAliases, - TEntities, - CRMEntityNames, -} from 'core/types/Entities/crmEntityNames'; +import { TEntities, CRMEntityNames } from 'core/types/Entities/crmEntityNames'; import { isPlural, singular } from 'pluralize'; const client = new ApolloClient({ @@ -64,6 +60,7 @@ class CalculationService { resEntities[targetName]; if (toOptions) + //@ts-ignore if (toOptions.includes(targetName)) { if (Array.isArray(targetEnt)) { let optionatedEntities: (TCRMEntity & IBaseOption)[] = []; @@ -79,7 +76,6 @@ class CalculationService { //@ts-ignore resEntities[ //@ts-ignore - !CRMEntityAliases.includes(targetName) && isPlural(targetName) ? singular(targetName) : targetName @@ -158,9 +154,7 @@ class CalculationService { //@ts-ignore resEntities[ //@ts-ignore - !CRMEntityAliases.includes(targetName) && isPlural(targetName) - ? singular(targetName) - : targetName + isPlural(targetName) ? singular(targetName) : targetName ] = optionatedEntities; } else { const entityOption = convertEntityToOption( diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 4802350..5f9dc39 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -90,7 +90,7 @@ const reactionEffects: IReactionEffect[] = [ CalculationService.crmgqlquery({ query: gql` query($evo_agent_accountid: Uuid!) { - agent: account(accountid: $evo_agent_accountid) { + account(accountid: $evo_agent_accountid) { accountid name } @@ -99,12 +99,17 @@ const reactionEffects: IReactionEffect[] = [ variables: { evo_agent_accountid: lead.evo_agent_accountid, }, - toOptions: ['agent'], + toOptions: ['account'], }).then(({ entities }) => { - if (entities.agent) { - if (!Array.isArray(entities.agent)) { - calculationStore.setOptions('selectIndAgent', [entities.agent]); - calculationStore.setValue('indAgent', entities.agent.accountid); + if (entities.account) { + if (!Array.isArray(entities.account)) { + calculationStore.setOptions('selectIndAgent', [ + entities.account, + ]); + calculationStore.setValue( + 'indAgent', + entities.account.accountid, + ); } } else { calculationStore.setValue('indAgent', null); @@ -120,7 +125,7 @@ const reactionEffects: IReactionEffect[] = [ CalculationService.crmgqlquery({ query: gql` query($evo_double_agent_accountid: Uuid!) { - double_agent: account(accountid: $evo_double_agent_accountid) { + account(accountid: $evo_double_agent_accountid) { accountid name } @@ -129,16 +134,16 @@ const reactionEffects: IReactionEffect[] = [ variables: { evo_double_agent_accountid: lead.evo_double_agent_accountid, }, - toOptions: ['double_agent'], + toOptions: ['account'], }).then(({ entities }) => { - if (entities.double_agent) { - if (!Array.isArray(entities.double_agent)) { + if (entities.account) { + if (!Array.isArray(entities.account)) { calculationStore.setOptions('selectCalcDoubleAgent', [ - entities.double_agent, + entities.account, ]); calculationStore.setValue( 'calcDoubleAgent', - entities.double_agent.accountid, + entities.account.accountid, ); } } else { @@ -155,7 +160,7 @@ const reactionEffects: IReactionEffect[] = [ CalculationService.crmgqlquery({ query: gql` query($evo_broker_accountid: Uuid!) { - broker: account(accountid: $evo_broker_accountid) { + account(accountid: $evo_broker_accountid) { accountid name } @@ -164,16 +169,16 @@ const reactionEffects: IReactionEffect[] = [ variables: { evo_broker_accountid: lead.evo_broker_accountid, }, - toOptions: ['broker'], + toOptions: ['account'], }).then(({ entities }) => { - if (entities.broker) { - if (!Array.isArray(entities.broker)) { + if (entities.account) { + if (!Array.isArray(entities.account)) { calculationStore.setOptions('selectCalcBroker', [ - entities.broker, + entities.account, ]); calculationStore.setValue( 'calcBroker', - entities.broker.accountid, + entities.account.accountid, ); } } @@ -187,9 +192,7 @@ const reactionEffects: IReactionEffect[] = [ CalculationService.crmgqlquery({ query: gql` query($evo_fin_department_accountid: Uuid!) { - findepartment: account( - accountid: $evo_fin_department_accountid - ) { + account(accountid: $evo_fin_department_accountid) { accountid name } @@ -198,16 +201,16 @@ const reactionEffects: IReactionEffect[] = [ variables: { evo_fin_department_accountid: lead.evo_fin_department_accountid, }, - toOptions: ['findepartment'], + toOptions: ['account'], }).then(({ entities }) => { - if (entities.findepartment) { - if (!Array.isArray(entities.findepartment)) { + if (entities.account) { + if (!Array.isArray(entities.account)) { calculationStore.setOptions('selectCalcFinDepartment', [ - entities.findepartment, + entities.account, ]); calculationStore.setValue( 'calcFinDepartment', - entities.findepartment.accountid, + entities.account.accountid, ); } } diff --git a/src/core/types/Calculation/Requests.ts b/src/core/types/Calculation/Requests.ts index abfa5b5..3856b72 100644 --- a/src/core/types/Calculation/Requests.ts +++ b/src/core/types/Calculation/Requests.ts @@ -1,7 +1,4 @@ -import { - CRMEntityAliasesUnion, - CRMEntityNames, -} from 'core/types/Entities/crmEntityNames'; +import { CRMEntityNames } from 'core/types/Entities/crmEntityNames'; import { TEntityQuery } from '../Entities/query'; import { ValuesTables } from './Store/tables'; import { TValue, TValues } from './Store/values'; @@ -12,7 +9,7 @@ export interface IGetEntitiesRequest { export interface IRequestToCRMGQL { query: any; - toOptions?: (CRMEntityNames | CRMEntityAliasesUnion)[]; + toOptions?: CRMEntityNames[]; variables: { [prop: string]: any }; } diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 009915b..43b5362 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -192,7 +192,7 @@ export interface IEvoCurrencyChange { evo_currencychange?: number; evo_coursedate?: Date; statecode?: number; - evo_coursedate_param: any; + evo_coursedate_param?: any; } export interface IEvoStatusCode { diff --git a/src/core/types/Entities/query.ts b/src/core/types/Entities/query.ts index f9bd681..1b1a341 100644 --- a/src/core/types/Entities/query.ts +++ b/src/core/types/Entities/query.ts @@ -1,6 +1,6 @@ // import { ElementsNames } from 'core/types/Calculation/Store/elements'; import { TCRMEntity } from './crmEntities'; -import { CRMEntityNames, CRMEntityAliasesUnion } from './crmEntityNames'; +import { CRMEntityNames } from './crmEntityNames'; import { ElementsNames } from 'core/types/Calculation/Store/elements'; export type ComparisonOperators = { @@ -16,7 +16,7 @@ export type TEntitiesKeys = keyof TCRMEntity; export type TWhere = { [prop in TEntitiesKeys]?: T }; export type TBaseEntityQuery = { - alias?: CRMEntityAliasesUnion | ElementsNames; + alias?: ElementsNames; entityName: CRMEntityNames; fields: [TEntitiesKeys, ...TEntitiesKeys[]]; relatedEntities?: TBaseEntityQuery[];