From ef9f340ba3ec9a4b9ab9a6dc2c376460824196ef Mon Sep 17 00:00:00 2001 From: Chika Date: Mon, 17 Jan 2022 23:53:49 +0300 Subject: [PATCH] CrmService: rm Promise wrapper & unnecessary types --- .../Effects/reactions/gibddReactions.ts | 13 +++--- .../Effects/reactions/loadKpReaction/index.ts | 2 +- .../Effects/reactions/requestReactions.ts | 4 +- .../stores/CalculationStore/init/variables.ts | 10 ++--- src/core/services/CrmService/index.ts | 42 ++++++++----------- src/core/services/CrmService/types/request.ts | 4 -- 6 files changed, 32 insertions(+), 43 deletions(-) delete mode 100644 src/core/services/CrmService/types/request.ts diff --git a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts index 88cf4d0..9eee9ac 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts @@ -463,9 +463,9 @@ const gibddReactions: IReactionEffect[] = [ ); if (evo_city_fias_id) { - CrmService.getCRMEntities<'evo_town', IEvoTown, IEvoTown>({ + CrmService.getCRMEntities<'evo_town', IEvoTown>({ query: gql` - query($evo_fias_id: String) { + query selectLegalClientTown($evo_fias_id: String) { evo_town(evo_fias_id: $evo_fias_id) { evo_fias_id evo_townid @@ -566,9 +566,9 @@ const gibddReactions: IReactionEffect[] = [ ); if (evo_city_fias_id && objectRegistration === 100000000) { - CrmService.getCRMEntities<'evo_town', IEvoTown, IEvoTown>({ + CrmService.getCRMEntities<'evo_town', IEvoTown>({ query: gql` - query($evo_fias_id: String) { + query selectTownRegistration($evo_fias_id: String) { evo_town(evo_fias_id: $evo_fias_id) { evo_fias_id evo_townid @@ -605,9 +605,8 @@ const gibddReactions: IReactionEffect[] = [ ]); }, effect: () => { - const objectRegistration = calculationStore.getValue( - 'objectRegistration', - ); + const objectRegistration = + calculationStore.getValue('objectRegistration'); if (objectRegistration === 100000001) { calculationStore.setFilter('selectTownRegistration', towns => towns.filter(x => x.evo_businessunit_evolution === true), diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index edb654e..3f8e4d1 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -88,7 +88,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ const { calculationProcess } = calculationStore.stores; - CrmService.getCRMEntities<'quote', IQuote, keyof IQuote>({ + CrmService.getCRMEntities<'quote', IQuote>({ query: getQuoteQuery, variables: { quoteId, diff --git a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts index f327cb1..5b338e1 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/requestReactions.ts @@ -213,7 +213,7 @@ export default [ ); } else { if (opportunity.parentaccountid) - CrmService.getCRMEntities<'account', IAccount, IAccount>({ + CrmService.getCRMEntities<'account', IAccount>({ query: gql` query clientRisk_1($accountid: Uuid!) { account(accountid: $accountid) { @@ -236,7 +236,7 @@ export default [ leadid, }); if (lead && lead.customerid) { - CrmService.getCRMEntities<'account', IAccount, IAccount>({ + CrmService.getCRMEntities<'account', IAccount>({ query: gql` query clientRisk_2($customerid: Uuid!) { account(accountid: $customerid) { diff --git a/src/client/stores/CalculationStore/init/variables.ts b/src/client/stores/CalculationStore/init/variables.ts index f356ce7..0419e37 100644 --- a/src/client/stores/CalculationStore/init/variables.ts +++ b/src/client/stores/CalculationStore/init/variables.ts @@ -1,9 +1,9 @@ -import { OperationVariables } from '@apollo/client'; -import { GQLVariables } from 'core/services/CrmService/types/request'; import { currentISODate } from 'core/tools/date'; import { IAccount, TCRMEntity } from 'core/types/Entities/crmEntities'; -export const mainOptionsVariables: OperationVariables = { +export const mainOptionsVariables: + | Partial> + | Record = { currentDate: currentISODate, statecode: 0, supplier_account_type: [100000001], @@ -20,12 +20,12 @@ export const mainOptionsVariables: OperationVariables = { fuelcard_product_type: 100000005, }; -export const insuranceVariables: GQLVariables = { +export const insuranceVariables: Partial> = { evo_account_type: [100000002], statecode: 0, }; -export const staticDataVariables: GQLVariables = { +export const staticDataVariables: Record = { statecode: 0, currentDate: currentISODate, }; diff --git a/src/core/services/CrmService/index.ts b/src/core/services/CrmService/index.ts index 0fdb2fa..88c17d7 100644 --- a/src/core/services/CrmService/index.ts +++ b/src/core/services/CrmService/index.ts @@ -5,34 +5,28 @@ import GQLClient from 'core/graphql/client'; import { ElementsNames } from 'core/types/Calculation/Store/elements'; import { IQuote, TCRMEntity } from 'core/types/Entities/crmEntities'; import { optionizeEntities } from './tools/entity'; -import { TOptionizedEntity } from './types/common'; -import { GQLVariables } from './types/request'; export default class { - public static getCRMEntities( - options: QueryOptions, Record>, - ): Promise>> { - return new Promise(resolve => { - GQLClient.query, GQLVariables>(options).then(res => - resolve(res.data), - ); - }); + public static getCRMEntities( + queryOptions: QueryOptions< + Partial> | Record, + Record + >, + ) { + return GQLClient.query< + Record, + Partial | Record> + >(queryOptions).then(res => res.data); } - public static getCRMOptions< - K extends string = ElementsNames, - R = TCRMEntity, - >({ - variables, - ...options - }: QueryOptions, Record>): Promise< - Partial[]>> - > { - return new Promise(resolve => - this.getCRMEntities({ - variables, - ...options, - }).then(entities => resolve(optionizeEntities(entities))), + public static getCRMOptions( + queryOptions: QueryOptions< + Partial> | Record, + Record + >, + ) { + return this.getCRMEntities(queryOptions).then(entities => + optionizeEntities(entities), ); } diff --git a/src/core/services/CrmService/types/request.ts b/src/core/services/CrmService/types/request.ts deleted file mode 100644 index 1245f40..0000000 --- a/src/core/services/CrmService/types/request.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { OperationVariables } from '@apollo/client'; - -export type GQLVariables = Partial> & - OperationVariables;