apps/web: add check min bonus

This commit is contained in:
vchikalkin 2024-08-20 15:52:21 +03:00
parent 194292c083
commit 5347c3ef6c

View File

@ -10,8 +10,17 @@ export function createValidationSchema(context: ValidationContext) {
return ValuesSchema.pick({ product: true, saleBonus: true }).superRefine(
async ({ product, saleBonus }, ctx) => {
const coefficient = await getCoefficient(product);
const minBonus = (coefficient?.evo_correction_coefficient || 0) * 100;
const maxBonus = (coefficient?.evo_sot_coefficient || 0) * 100;
if (round(saleBonus, 2) < round(minBonus, 2)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Бонус не может быть ниже установленного по СОТ',
path: ['tbxSaleBonus'],
});
}
if (round(saleBonus, 2) > round(maxBonus, 2)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,