validation: add create-kp required fields

This commit is contained in:
vchikalkin 2023-04-19 17:28:19 +03:00
parent 99d7af4ac6
commit 870a9b5d75
2 changed files with 46 additions and 0 deletions

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 * as CRMTypes from '@/graphql/crm.types';
@ -5,13 +7,16 @@ import { z } from 'zod';
export function createValidationSchema({ apolloClient }: ValidationContext) {
return ValuesSchema.pick({
brand: true,
countSeats: true,
engineType: true,
engineVolume: true,
leaseObjectCategory: true,
leaseObjectMotorPower: true,
leaseObjectType: true,
leaseObjectUseFor: true,
maxMass: true,
model: true,
}).superRefine(
async (
{
@ -22,9 +27,44 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
countSeats,
maxMass,
leaseObjectCategory,
brand,
model,
leaseObjectUseFor,
},
ctx
) => {
if (!leaseObjectTypeId) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectLeaseObjectType'],
});
}
if (!brand) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectBrand'],
});
}
if (!model) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectModel'],
});
}
if (!leaseObjectUseFor) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectLeaseObjectUseFor'],
});
}
if (leaseObjectTypeId) {
const {
data: { evo_leasingobject_type },

View File

@ -369,6 +369,12 @@ export function createValidationSchema(context: ValidationContext) {
message: 'Не заполнено поле',
path: ['selectDealerPerson'],
});
} else {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Не заполнено поле',
path: ['selectDealer'],
});
}
const { validateRewardSum, validateRewardWithoutOtherAgent } = helper({ ...context, ctx });