From 6a445e2838f33111faca9eed75c8aaf6463aa863 Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 3 Dec 2020 16:14:04 +0300 Subject: [PATCH] load lead & opportunity by username --- .../Calculation/lib/fetchData/index.js | 13 +++++++- .../fetchData/queries/initialOwnerQuery.ts | 26 +++++++++++++++ .../lib/fetchData/queries/optionsQuery.ts | 32 ------------------- src/core/types/Entities/crmEntities.ts | 1 + 4 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 src/client/Containers/Calculation/lib/fetchData/queries/initialOwnerQuery.ts diff --git a/src/client/Containers/Calculation/lib/fetchData/index.js b/src/client/Containers/Calculation/lib/fetchData/index.js index 5ab0c45..50ba23d 100644 --- a/src/client/Containers/Calculation/lib/fetchData/index.js +++ b/src/client/Containers/Calculation/lib/fetchData/index.js @@ -6,12 +6,21 @@ import insuranceQuery from './queries/insuranceQuery'; import optionsQuery from './queries/optionsQuery'; import staticDataQuery from './queries/staticDataQuery'; import systemUserQuery from './queries/systemUserQuery'; +import initialOwnerQuery from './queries/initialOwnerQuery'; export default () => new Promise((resolve, reject) => { getUser() - .then(({ UserName, DomainName }) => { + .then(({ UserName, DomainName, FullName }) => { Promise.all([ + CrmService.crmgqlquery({ + query: initialOwnerQuery, + variables: { + statecode: 0, + fullName: FullName, + }, + toOptions: ['selectLead', 'selectOpportunity'], + }), CrmService.getEntities({ queries: optionsQuery, }), @@ -32,6 +41,7 @@ export default () => ]) .then( ([ + { entities: ownerOptions }, { entities: initialOptions }, { entities: staticEntities }, { @@ -39,6 +49,7 @@ export default () => }, { entities: insuranceCompanies }, ]) => { + CalculationStore.applyOptions(ownerOptions); CalculationStore.applyOptions(initialOptions); CalculationStore.applyStaticData(staticEntities); CalculationStore.applyStaticData({ systemuser: [systemuser] }); diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/initialOwnerQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/initialOwnerQuery.ts new file mode 100644 index 0000000..da5b8ad --- /dev/null +++ b/src/client/Containers/Calculation/lib/fetchData/queries/initialOwnerQuery.ts @@ -0,0 +1,26 @@ +import { gql } from '@apollo/client'; +export default gql` + query($statecode: Int, $fullName: String) { + selectLead: leads(statecode: $statecode, owner_domainname: $fullName) { + customerid + leadid + fullname + evo_opportunityid + evo_agent_accountid + evo_double_agent_accountid + evo_broker_accountid + evo_fin_department_accountid + } + selectOpportunity: opportunities( + statecode: $statecode + owner_domainname: $fullName + ) { + opportunityid + name + accountid + evo_leadid + evo_client_riskid + parentaccountid + } + } +`; diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts index 3e303a1..4327e7a 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts @@ -2,38 +2,6 @@ import { TEntityQuery } from 'core/types/Entities/query'; import { currentDate } from 'client/tools/date'; const initialOptionsQuery: TEntityQuery[] = [ - { - alias: 'selectLead', - entityName: 'lead', - fields: [ - 'customerid', - 'leadid', - 'fullname', - 'evo_opportunityid', - 'evo_agent_accountid', - 'evo_double_agent_accountid', - 'evo_broker_accountid', - 'evo_fin_department_accountid', - ], - where: { statecode: 0 }, - many: true, - toOption: true, - }, - { - alias: 'selectOpportunity', - entityName: 'opportunity', - fields: [ - 'opportunityid', - 'name', - 'accountid', - 'evo_leadid', - 'evo_client_riskid', - 'parentaccountid', - ], - where: { statecode: 0 }, - many: true, - toOption: true, - }, { alias: 'selectSupplier', entityName: 'account', diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 6c58aea..628a2e9 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -28,6 +28,7 @@ export interface ILead { evo_double_agent_accountid?: string; evo_agent_accountid?: string; accountidData?: IAccount; + owner_domainname?: string; } export interface IOpportunity {