51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import type { ValidationContext } from '../../types';
|
|
import type { ElementsTypes } from '@/Components/Calculation/config/map/values';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import { getCurrentDateString } from '@/utils/date';
|
|
|
|
export type ProductId = ElementsTypes['selectProduct'];
|
|
|
|
export default function helper({ apolloClient, user }: ValidationContext) {
|
|
return {
|
|
async getCoefficient(productId: ProductId) {
|
|
if (!productId || !user) {
|
|
return null;
|
|
}
|
|
|
|
const {
|
|
data: { systemusers },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetSystemUserDocument,
|
|
variables: {
|
|
domainname: user.domainName,
|
|
},
|
|
});
|
|
|
|
const systemuser = systemusers?.[0];
|
|
|
|
if (!systemuser?.evo_job_titleid) {
|
|
return null;
|
|
}
|
|
|
|
const currentDate = getCurrentDateString();
|
|
|
|
const {
|
|
data: { evo_coefficients },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetCoefficientsDocument,
|
|
variables: {
|
|
currentDate,
|
|
jobTitleId: systemuser?.evo_job_titleid,
|
|
},
|
|
});
|
|
|
|
return evo_coefficients?.find(
|
|
(evo_coefficient) =>
|
|
evo_coefficient?.evo_job_titleid === systemuser.evo_job_titleid &&
|
|
evo_coefficient?.evo_sot_coefficient_typeidData?.evo_id === 'BONUS_LEASING' &&
|
|
evo_coefficient?.evo_baseproducts?.some((x) => x?.evo_baseproductid === productId)
|
|
);
|
|
},
|
|
};
|
|
}
|