/* eslint-disable import/prefer-default-export */ import type { ApolloClient, NormalizedCache } from '@apollo/client'; import { gql } from '@apollo/client'; import { getDomainName } from 'services/user/tools'; import type { User } from 'services/user/types'; import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData'; import type { GetTransactionCurrencies } from './__generated__/GetTransactionCurrencies'; const QUERY_GET_OWNER_DATA = gql` query GetOwnerData($domainname: String) { selectLead: leads(owner_domainname: $domainname) { label: fullname value: leadid } selectOpportunity: opportunities(owner_domainname: $domainname) { label: name value: opportunityid } } `; const QUERY_GET_TRANSACTION_CURRENCIES = gql` query GetTransactionCurrencies { selectSupplierCurrency: transactioncurrencies { label: currencyname currencysymbol value: transactioncurrencyid } } `; export async function getCRMData(apolloClient: ApolloClient, user: User) { const { data: { selectLead, selectOpportunity }, } = await apolloClient.query({ query: QUERY_GET_OWNER_DATA, variables: { domainname: getDomainName(user), }, }); // prettier-ignore const { data: { selectSupplierCurrency } } = await apolloClient.query({ query: QUERY_GET_TRANSACTION_CURRENCIES, }); return { options: { selectLead, selectOpportunity, selectSupplierCurrency, }, }; }