CrmService: rm Promise wrapper & unnecessary types
This commit is contained in:
parent
04628a92aa
commit
ef9f340ba3
@ -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),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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<keyof TCRMEntity, any>>
|
||||
| Record<string, any> = {
|
||||
currentDate: currentISODate,
|
||||
statecode: 0,
|
||||
supplier_account_type: [100000001],
|
||||
@ -20,12 +20,12 @@ export const mainOptionsVariables: OperationVariables = {
|
||||
fuelcard_product_type: 100000005,
|
||||
};
|
||||
|
||||
export const insuranceVariables: GQLVariables<IAccount> = {
|
||||
export const insuranceVariables: Partial<Record<keyof IAccount, any>> = {
|
||||
evo_account_type: [100000002],
|
||||
statecode: 0,
|
||||
};
|
||||
|
||||
export const staticDataVariables: GQLVariables<keyof TCRMEntity> = {
|
||||
export const staticDataVariables: Record<string, any> = {
|
||||
statecode: 0,
|
||||
currentDate: currentISODate,
|
||||
};
|
||||
|
||||
@ -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<K extends string, R, V = TCRMEntity>(
|
||||
options: QueryOptions<GQLVariables<V>, Record<K, R>>,
|
||||
): Promise<Partial<Record<K, R>>> {
|
||||
return new Promise(resolve => {
|
||||
GQLClient.query<Record<K, R>, GQLVariables<V>>(options).then(res =>
|
||||
resolve(res.data),
|
||||
);
|
||||
});
|
||||
public static getCRMEntities<K extends string, R>(
|
||||
queryOptions: QueryOptions<
|
||||
Partial<Record<keyof R, any>> | Record<string, any>,
|
||||
Record<K, R>
|
||||
>,
|
||||
) {
|
||||
return GQLClient.query<
|
||||
Record<K, R>,
|
||||
Partial<Record<keyof R, any> | Record<string, any>>
|
||||
>(queryOptions).then(res => res.data);
|
||||
}
|
||||
|
||||
public static getCRMOptions<
|
||||
K extends string = ElementsNames,
|
||||
R = TCRMEntity,
|
||||
>({
|
||||
variables,
|
||||
...options
|
||||
}: QueryOptions<GQLVariables<R>, Record<K, R>>): Promise<
|
||||
Partial<Record<K, TOptionizedEntity<R>[]>>
|
||||
> {
|
||||
return new Promise(resolve =>
|
||||
this.getCRMEntities<K, R | R[], keyof typeof variables>({
|
||||
variables,
|
||||
...options,
|
||||
}).then(entities => resolve(optionizeEntities<K, R>(entities))),
|
||||
public static getCRMOptions<K extends string = ElementsNames, R = TCRMEntity>(
|
||||
queryOptions: QueryOptions<
|
||||
Partial<Record<keyof R, any>> | Record<string, any>,
|
||||
Record<K, R>
|
||||
>,
|
||||
) {
|
||||
return this.getCRMEntities<K, R | R[]>(queryOptions).then(entities =>
|
||||
optionizeEntities<K, R>(entities),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
import { OperationVariables } from '@apollo/client';
|
||||
|
||||
export type GQLVariables<R> = Partial<Record<keyof R, any>> &
|
||||
OperationVariables;
|
||||
Reference in New Issue
Block a user