/* 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 { GetInsuranceData } from './__generated__/GetInsuranceData'; 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 } } `; const QUERY_GET_INSURANCE_DATA = gql` query GetInsuranceData($evo_account_type: [Int!]) { osago: accounts( evo_account_type: $evo_account_type evo_type_ins_policy: [100000001] statecode: 0 ) { value: accountid label: name } kasko: accounts( evo_account_type: $evo_account_type evo_type_ins_policy: [100000000] statecode: 0 ) { value: accountid label: name } finGAP: accounts( evo_account_type: $evo_account_type evo_type_ins_policy: [100000002] statecode: 0 ) { value: accountid label: name } } `; 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, }); const { data: insuranceData } = await apolloClient.query({ query: QUERY_GET_INSURANCE_DATA, }); return { options: { selectLead, selectOpportunity, selectSupplierCurrency, }, tables: { insurance: insuranceData, }, }; }