Если Плавающая ставка = Да и Лизинг без КАСКО содержит данные,

то выводить сообщение "При плавающей ставке нельзя оформлять Лизинг без КАСКО"
This commit is contained in:
vchikalkin 2024-01-31 10:27:24 +03:00
parent 65db1c0536
commit 8bdbbaab51

View File

@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import type { ValidationContext } from '../types'; import type { ValidationContext } from '../types';
import elementsProps from '@/Components/Calculation/config/elements-props'; import elementsProps from '@/Components/Calculation/config/elements-props';
import { getElementName } from '@/Components/Calculation/config/map/values'; import { getElementName } from '@/Components/Calculation/config/map/values';
@ -24,6 +25,7 @@ const Schema = ValuesSchema.pick({
finDepartmentRewardSumm: true, finDepartmentRewardSumm: true,
firstPaymentPerc: true, firstPaymentPerc: true,
firstPaymentRub: true, firstPaymentRub: true,
floatingRate: true,
importProgramSum: true, importProgramSum: true,
importerRewardPerc: true, importerRewardPerc: true,
importerRewardRub: true, importerRewardRub: true,
@ -38,6 +40,7 @@ const Schema = ValuesSchema.pick({
leaseObjectPriceWthtVAT: true, leaseObjectPriceWthtVAT: true,
leaseObjectYear: true, leaseObjectYear: true,
leasingPeriod: true, leasingPeriod: true,
leasingWithoutKasko: true,
maxMass: true, maxMass: true,
maxPriceChange: true, maxPriceChange: true,
maxSpeed: true, maxSpeed: true,
@ -93,6 +96,19 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
} }
} }
/**
* Если Плавающая ставка = Да и Лизинг без КАСКО содержит данные,
* то выводить сообщение "При плавающей ставке нельзя оформлять Лизинг без КАСКО"
*/
const { floatingRate, leasingWithoutKasko } = values;
if (floatingRate && leasingWithoutKasko) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'При плавающей ставке нельзя оформлять Лизинг без КАСКО',
path: ['selectLeasingWithoutKasko'],
});
}
(Object.keys(values) as Values[]).forEach((valueName) => { (Object.keys(values) as Values[]).forEach((valueName) => {
const elementName = getElementName(valueName); const elementName = getElementName(valueName);
if (elementName) { if (elementName) {