From 6adb1be0cf6b89f4c7218104f2f30b73d54663b0 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 21 Apr 2023 11:05:47 +0300 Subject: [PATCH] process/leasing-object: add selectConfiguration validation --- apps/web/process/leasing-object/validation.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/web/process/leasing-object/validation.ts b/apps/web/process/leasing-object/validation.ts index c6abbb3..beec27d 100644 --- a/apps/web/process/leasing-object/validation.ts +++ b/apps/web/process/leasing-object/validation.ts @@ -8,6 +8,7 @@ import { z } from 'zod'; export function createValidationSchema({ apolloClient }: ValidationContext) { return ValuesSchema.pick({ brand: true, + configuration: true, countSeats: true, engineType: true, engineVolume: true, @@ -30,6 +31,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { brand, model, leaseObjectUseFor, + configuration, }, ctx ) => { @@ -57,6 +59,23 @@ export function createValidationSchema({ apolloClient }: ValidationContext) { }); } + if (model && !configuration) { + const { + data: { evo_equipments }, + } = await apolloClient.query({ + query: CRMTypes.GetConfigurationsDocument, + variables: { modelId: model }, + }); + + if (evo_equipments?.length) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Не заполнено поле', + path: ['selectConfiguration'], + }); + } + } + if (!leaseObjectUseFor) { ctx.addIssue({ code: z.ZodIssueCode.custom,