fix tbxLastPaymentPerc validation

This commit is contained in:
vchikalkin 2023-04-17 15:05:26 +03:00
parent 622f4e75ed
commit 2e74b1a23c
2 changed files with 21 additions and 19 deletions

View File

@ -8,7 +8,9 @@ import { z } from 'zod';
export function createValidationSchema({ apolloClient }: ValidationContext) {
return ValuesSchema.pick({
VATInLeaseObjectPrice: true,
balanceHolder: true,
firstPaymentRub: true,
lastPaymentPerc: true,
leaseObjectPriceWthtVAT: true,
plPriceRub: true,
product: true,
@ -24,6 +26,8 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
plPriceRub,
firstPaymentRub,
subsidySum,
balanceHolder,
lastPaymentPerc,
},
ctx
) => {
@ -74,6 +78,23 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
path: ['tbxFirstPaymentRub'],
});
}
if (balanceHolder === 100_000_001) {
if (lastPaymentPerc < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.',
path: ['tbxLastPaymentPerc'],
});
}
} else if (lastPaymentPerc === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Последний платеж не может быть равен 0. Увеличьте значение',
path: ['tbxLastPaymentPerc'],
});
}
}
);
}

View File

@ -9,7 +9,6 @@ import { z } from 'zod';
export function createValidationSchema({ apolloClient }: ValidationContext) {
return ValuesSchema.pick({
addEquipmentPrice: true,
balanceHolder: true,
countSeats: true,
dealerPerson: true,
discountRub: true,
@ -45,7 +44,6 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
countSeats,
leaseObjectYear,
lastPaymentPerc,
balanceHolder,
leaseObjectCategory,
},
ctx
@ -236,23 +234,6 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
path: ['tbxLastPaymentPerc'],
});
}
if (balanceHolder === 100_000_001) {
if (lastPaymentPerc < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
'При балансе лизингодатель последний платеж не может быть меньше 1%! Увеличьте значение.',
path: ['tbxLastPaymentPerc'],
});
}
} else if (lastPaymentPerc === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Последний платеж не может быть равен 0. Увеличьте значение',
path: ['tbxLastPaymentPerc'],
});
}
}
}
);