From df708e40ae0997ba3265731a4429c48a0afc3643 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 13 Apr 2023 11:47:33 +0300 Subject: [PATCH] =?UTF-8?q?process/gibdd:=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B8=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/process/gibdd/reactions.ts | 6 +++ apps/web/process/gibdd/validation.ts | 66 ++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/apps/web/process/gibdd/reactions.ts b/apps/web/process/gibdd/reactions.ts index 87b3bac..23b3e03 100644 --- a/apps/web/process/gibdd/reactions.ts +++ b/apps/web/process/gibdd/reactions.ts @@ -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) { diff --git a/apps/web/process/gibdd/validation.ts b/apps/web/process/gibdd/validation.ts index b1fb526..d7681df 100644 --- a/apps/web/process/gibdd/validation.ts +++ b/apps/web/process/gibdd/validation.ts @@ -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'], }); - } } ); }