diff --git a/process/agents/lib/__generated__/GetBroker.ts b/process/agents/lib/__generated__/GetBroker.ts deleted file mode 100644 index d14e58a..0000000 --- a/process/agents/lib/__generated__/GetBroker.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: GetBroker -// ==================================================== - -export interface GetBroker_agent { - __typename: "account"; - label: string | null; - value: any | null; -} - -export interface GetBroker { - agent: GetBroker_agent | null; -} - -export interface GetBrokerVariables { - agentid: any; -} diff --git a/process/agents/lib/__generated__/GetDoubleAgent.ts b/process/agents/lib/__generated__/GetDoubleAgent.ts deleted file mode 100644 index 7f5f1c6..0000000 --- a/process/agents/lib/__generated__/GetDoubleAgent.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: GetDoubleAgent -// ==================================================== - -export interface GetDoubleAgent_agent { - __typename: "account"; - label: string | null; - value: any | null; -} - -export interface GetDoubleAgent { - agent: GetDoubleAgent_agent | null; -} - -export interface GetDoubleAgentVariables { - agentid: any; -} diff --git a/process/agents/lib/__generated__/GetFinDepartment.ts b/process/agents/lib/__generated__/GetFinDepartment.ts deleted file mode 100644 index df3db72..0000000 --- a/process/agents/lib/__generated__/GetFinDepartment.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: GetFinDepartment -// ==================================================== - -export interface GetFinDepartment_agent { - __typename: "account"; - label: string | null; - value: any | null; -} - -export interface GetFinDepartment { - agent: GetFinDepartment_agent | null; -} - -export interface GetFinDepartmentVariables { - agentid: any; -} diff --git a/process/agents/lib/fill-agents-from-lead.ts b/process/agents/lib/fill-agents-from-lead.ts index 488e8dd..2fec5d7 100644 --- a/process/agents/lib/fill-agents-from-lead.ts +++ b/process/agents/lib/fill-agents-from-lead.ts @@ -4,13 +4,15 @@ import { gql } from '@apollo/client'; import type { Elements } from 'Components/Calculation/config/map/values'; import type RootStore from 'stores/root'; import { normalizeOptions } from 'tools/entity'; +import QueryGetAgent from './query/GetAgent.graphql'; +import type { GetAgent } from './query/__generated__/GetAgent'; -function fillAgent( +function makeFillAgent( elementName: Elements, queryGetAgentId: DocumentNode, queryGetAgent: DocumentNode ) { - return async function ( + return async function fillAgent( { $calculation }: RootStore, apolloClient: ApolloClient, leadid: string | null @@ -33,7 +35,7 @@ function fillAgent( if (lead?.agentid) { const { data: { agent }, - } = await apolloClient.query({ + } = await apolloClient.query({ query: queryGetAgent, variables: { agentid: lead.agentid, @@ -64,16 +66,11 @@ const QUERY_GET_AGENT_ACCOUNTID = gql` } `; -const QUERY_GET_AGENT = gql` - query GetAgent($agentid: Uuid!) { - agent: account(accountid: $agentid) { - label: name - value: accountid - } - } -`; - -export const fillIndAgent = fillAgent('selectIndAgent', QUERY_GET_AGENT_ACCOUNTID, QUERY_GET_AGENT); +export const fillIndAgent = makeFillAgent( + 'selectIndAgent', + QUERY_GET_AGENT_ACCOUNTID, + QueryGetAgent +); /** * Если lead содержит данные, @@ -90,19 +87,10 @@ const QUERY_GET_DOUBLE_AGENT_ACCOUNTID = gql` } `; -const QUERY_GET_DOUBLE_AGENT = gql` - query GetDoubleAgent($agentid: Uuid!) { - agent: account(accountid: $agentid) { - label: name - value: accountid - } - } -`; - -export const fillCalcDoubleAgent = fillAgent( +export const fillCalcDoubleAgent = makeFillAgent( 'selectCalcDoubleAgent', QUERY_GET_DOUBLE_AGENT_ACCOUNTID, - QUERY_GET_DOUBLE_AGENT + QueryGetAgent ); /** @@ -119,19 +107,10 @@ const QUERY_GET_BROKER_ACCOUNTID = gql` } `; -const QUERY_GET_BROKER = gql` - query GetBroker($agentid: Uuid!) { - agent: account(accountid: $agentid) { - label: name - value: accountid - } - } -`; - -export const fillCalcBroker = fillAgent( +export const fillCalcBroker = makeFillAgent( 'selectCalcBroker', QUERY_GET_BROKER_ACCOUNTID, - QUERY_GET_BROKER + QueryGetAgent ); /** @@ -149,17 +128,8 @@ const QUERY_GET_FIN_DEPARTMENT_ACCOUNTID = gql` } `; -const QUERY_GET_FIN_DEPARTMENT = gql` - query GetFinDepartment($agentid: Uuid!) { - agent: account(accountid: $agentid) { - label: name - value: accountid - } - } -`; - -export const fillFinDepartment = fillAgent( +export const fillFinDepartment = makeFillAgent( 'selectCalcFinDepartment', QUERY_GET_FIN_DEPARTMENT_ACCOUNTID, - QUERY_GET_FIN_DEPARTMENT + QueryGetAgent ); diff --git a/process/agents/lib/query/GetAgent.graphql b/process/agents/lib/query/GetAgent.graphql new file mode 100644 index 0000000..5be5841 --- /dev/null +++ b/process/agents/lib/query/GetAgent.graphql @@ -0,0 +1,6 @@ +query GetAgent($agentid: Uuid!) { + agent: account(accountid: $agentid) { + label: name + value: accountid + } +} diff --git a/process/agents/lib/__generated__/GetAgent.ts b/process/agents/lib/query/__generated__/GetAgent.ts similarity index 100% rename from process/agents/lib/__generated__/GetAgent.ts rename to process/agents/lib/query/__generated__/GetAgent.ts