65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
import type { ProcessContext } from '../../../types';
|
|
import { getUser } from '@/api/user/query';
|
|
import type { ElementsTypes } from '@/Components/Calculation/config/map/values';
|
|
import { STALE_TIME } from '@/constants/request';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import dayjs from 'dayjs';
|
|
|
|
export type ProductId = ElementsTypes['selectProduct'];
|
|
|
|
export default function helper({ apolloClient, queryClient }: ProcessContext) {
|
|
return {
|
|
async getCoefficient(productId: ProductId) {
|
|
if (!productId) {
|
|
return null;
|
|
}
|
|
|
|
const user = await queryClient.fetchQuery(['user'], () => getUser(), {
|
|
staleTime: STALE_TIME,
|
|
});
|
|
|
|
const {
|
|
data: { systemuser },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetSystemUserDocument,
|
|
variables: {
|
|
domainname: user.domainName,
|
|
},
|
|
});
|
|
|
|
if (!systemuser?.evo_job_titleid) {
|
|
return null;
|
|
}
|
|
|
|
const currentDate = dayjs().utc(false).toISOString();
|
|
|
|
const {
|
|
data: { evo_coefficients },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetCoefficientsDocument,
|
|
variables: {
|
|
currentDate,
|
|
jobTitleId: systemuser?.evo_job_titleid,
|
|
},
|
|
});
|
|
|
|
const {
|
|
data: { evo_sot_coefficient_type },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetSotCoefficientTypeDocument,
|
|
variables: {
|
|
evo_id: 'BONUS_LEASING',
|
|
},
|
|
});
|
|
|
|
return evo_coefficients?.find(
|
|
(evo_coefficient) =>
|
|
evo_coefficient?.evo_sot_coefficient_typeid ===
|
|
evo_sot_coefficient_type?.evo_sot_coefficient_typeid &&
|
|
evo_coefficient?.evo_baseproducts?.some((x) => x?.evo_baseproductid === productId)
|
|
);
|
|
},
|
|
};
|
|
}
|