get calculation values types from zod schema add loadKP reaction get base agents data from kp
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { gql } from '@apollo/client';
|
|
import initializeApollo from 'apollo/client';
|
|
import type {
|
|
GetAgentsDataFromQuoteQuery,
|
|
GetAgentsDataFromQuoteQueryVariables,
|
|
} from 'graphql/crm.types';
|
|
import type { CalculationValues } from 'stores/calculation/values/types';
|
|
|
|
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
|
query GetAgentsDataFromQuote($quoteId: Uuid!) {
|
|
quote(quoteId: $quoteId) {
|
|
evo_supplier_accountid
|
|
evo_dealer_person_accountid
|
|
evo_dealer_reward_conditionid
|
|
evo_dealer_reward_total
|
|
evo_dealer_broker_accountid
|
|
evo_dealer_broker_reward_conditionid
|
|
evo_dealer_broker_reward_total
|
|
evo_agent_accountid
|
|
evo_agent_reward_conditionid
|
|
evo_agent_reward_total
|
|
evo_double_agent_accountid
|
|
evo_double_agent_reward_conditionid
|
|
evo_double_agent_reward_total
|
|
evo_broker_accountid
|
|
evo_broker_reward_conditionid
|
|
evo_broker_reward_total
|
|
evo_fin_department_accountid
|
|
evo_fin_department_reward_conditionid
|
|
evo_fin_department_reward_total
|
|
}
|
|
}
|
|
`;
|
|
|
|
type SupplierData = {
|
|
values: Partial<CalculationValues>;
|
|
};
|
|
|
|
export default async function getSupplierAgentsDataFromKP(
|
|
values: CalculationValues
|
|
): Promise<SupplierData> {
|
|
const apolloClient = initializeApollo();
|
|
|
|
const {
|
|
data: { quote },
|
|
} = await apolloClient.query<GetAgentsDataFromQuoteQuery, GetAgentsDataFromQuoteQueryVariables>({
|
|
query: QUERY_GET_AGENTS_DATA_FROM_QUOTE,
|
|
variables: {
|
|
quoteId: values.quote!,
|
|
},
|
|
});
|
|
|
|
return {
|
|
values: {
|
|
dealer: quote?.evo_supplier_accountid,
|
|
dealerRewardCondition: quote?.evo_dealer_reward_conditionid,
|
|
dealerBroker: quote?.evo_dealer_broker_accountid,
|
|
dealerBrokerRewardCondition: quote?.evo_dealer_broker_reward_conditionid,
|
|
calcDoubleAgent: quote?.evo_double_agent_accountid,
|
|
calcDoubleAgentRewardCondition: quote?.evo_double_agent_reward_conditionid,
|
|
},
|
|
};
|
|
}
|