process/gibdd: дополнили валидацию

This commit is contained in:
vchikalkin 2023-04-13 11:47:33 +03:00
parent 7b96fc7b8b
commit df708e40ae
2 changed files with 63 additions and 9 deletions

View File

@ -528,8 +528,14 @@ export function validation(context: ProcessContext) {
'objectCategoryTax',
'insNSIB',
'vehicleTaxInYear',
'vehicleTaxInLeasingPeriod',
'objectRegionRegistration',
'regionRegistration',
'townRegistration',
'registration',
]),
async (values) => {
validationHelper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (validationResult.success === false) {

View File

@ -1,3 +1,5 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable complexity */
import type { ValidationContext } from '../types';
import ValuesSchema from '@/config/schema/values';
import { MAX_MASS } from '@/constants/values';
@ -11,8 +13,13 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
leaseObjectType: true,
maxMass: true,
objectCategoryTax: true,
objectRegionRegistration: true,
objectRegistration: true,
regionRegistration: true,
registration: true,
townRegistration: true,
typePTS: true,
vehicleTaxInLeasingPeriod: true,
vehicleTaxInYear: true,
}).superRefine(
async (
@ -25,6 +32,11 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
objectCategoryTax,
insNSIB,
vehicleTaxInYear,
vehicleTaxInLeasingPeriod,
objectRegionRegistration,
regionRegistration,
townRegistration,
registration,
},
ctx
) => {
@ -74,21 +86,57 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
}
}
if (objectRegistration === 100_000_001 && !(vehicleTaxInYear > 0)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Значение должно быть больше 0',
path: ['tbxVehicleTaxInYear'],
});
if (objectRegistration === 100_000_001) {
if (!(vehicleTaxInYear > 0))
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Значение должно быть больше 0',
path: ['tbxVehicleTaxInYear'],
});
if (!(vehicleTaxInLeasingPeriod > 0))
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Значение должно быть больше 0',
path: ['tbxVehicleTaxInLeasingPeriod'],
});
if (!objectRegionRegistration)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectObjectRegionRegistration'],
});
if (!typePTS) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['radioTypePTS'],
});
}
}
if (objectRegistration === 100_000_001 && !typePTS) {
if (objectRegistration === 100_000_000 && !townRegistration)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['radioTypePTS'],
path: ['selectTownRegistration'],
});
if (!regionRegistration)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectRegionRegistration'],
});
if (!registration)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectRegistration'],
});
}
}
);
}