53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import ValuesSchema from '@/config/schema/values';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import type { ProcessContext } from '@/process/types';
|
|
import type { z } from 'zod';
|
|
|
|
const InputSchema = ValuesSchema.pick({
|
|
bonusCoefficient: true,
|
|
product: true,
|
|
tarif: true,
|
|
});
|
|
|
|
export default function helper({ apolloClient }: Pick<ProcessContext, 'apolloClient'>) {
|
|
return {
|
|
async getIrr({
|
|
product: productId,
|
|
tarif: tarifId,
|
|
bonusCoefficient,
|
|
}: z.infer<typeof InputSchema>) {
|
|
let max = 0;
|
|
let min = 0;
|
|
|
|
if (productId && tarifId) {
|
|
const {
|
|
data: { evo_baseproduct },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetProductDocument,
|
|
variables: {
|
|
productId,
|
|
},
|
|
});
|
|
|
|
const {
|
|
data: { evo_tarif },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetTarifDocument,
|
|
variables: {
|
|
tarifId,
|
|
},
|
|
});
|
|
|
|
min = evo_tarif?.evo_min_irr ?? 0;
|
|
max = evo_tarif?.evo_max_irr ?? 0;
|
|
|
|
if (evo_baseproduct?.evo_cut_irr_with_bonus && bonusCoefficient < 1) {
|
|
min -= (1 - bonusCoefficient) * (evo_tarif?.evo_cut_irr_with_bonus_coefficient ?? 0);
|
|
}
|
|
}
|
|
|
|
return { max, min };
|
|
},
|
|
};
|
|
}
|