2023-03-16 19:45:03 +03:00

25 lines
850 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ValidationContext } from '../types';
import helper from './lib/helper';
import ValuesSchema from '@/config/schema/values';
import { round } from 'tools';
import { z } from 'zod';
export function createValidationSchema(context: ValidationContext) {
const { getCoefficient } = helper(context);
return ValuesSchema.pick({ product: true, saleBonus: true }).superRefine(
async ({ product, saleBonus }, ctx) => {
const coefficient = await getCoefficient(product);
const maxBonus = (coefficient?.evo_sot_coefficient || 0) * 100;
if (round(saleBonus, 2) > round(maxBonus, 2)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Бонус не может быть выше установленного по СОТ',
path: ['tbxSaleBonus'],
});
}
}
);
}