в lease-object, выделяем tbxMaxSpeed Если Тип предмета лизинга selectLeaseObjectType = Спецтехника (ID=9) или Погрузчик (ID=6) или Трактор (ID=10) И значение в поле tbxMaxSpeed= 0, то выводить сообщение "Необходимо указать Макс. констр. скорость (при ПСМ)" в insurance выделяем selectLeaseObjectType Если Тип предмета лизинга selectLeaseObjectType = Спецтехника (ID=9) и значение в поле tbxMaxSpeed< 20 и insuredOSAGO = Лизингодатель (100000001), то выводить сообщение "Нельзя включать в график ОСАГО по Спецтехнике, т.к. полис не требуется"
195 lines
5.3 KiB
TypeScript
195 lines
5.3 KiB
TypeScript
/* 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';
|
||
import { z } from 'zod';
|
||
|
||
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||
return ValuesSchema.pick({
|
||
brand: true,
|
||
configuration: true,
|
||
countSeats: true,
|
||
engineType: true,
|
||
engineVolume: true,
|
||
leaseObjectCategory: true,
|
||
leaseObjectMotorPower: true,
|
||
leaseObjectType: true,
|
||
leaseObjectUseFor: true,
|
||
maxMass: true,
|
||
maxSpeed: true,
|
||
model: true,
|
||
}).superRefine(
|
||
async (
|
||
{
|
||
leaseObjectType: leaseObjectTypeId,
|
||
engineVolume,
|
||
engineType,
|
||
leaseObjectMotorPower,
|
||
countSeats,
|
||
maxMass,
|
||
leaseObjectCategory,
|
||
brand,
|
||
model: modelId,
|
||
leaseObjectUseFor,
|
||
configuration,
|
||
maxSpeed,
|
||
},
|
||
ctx
|
||
) => {
|
||
if (!leaseObjectTypeId) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectLeaseObjectType'],
|
||
});
|
||
}
|
||
|
||
if (!brand) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectBrand'],
|
||
});
|
||
}
|
||
|
||
if (!modelId) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectModel'],
|
||
});
|
||
}
|
||
|
||
if (modelId && !configuration) {
|
||
const {
|
||
data: { evo_equipments },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetConfigurationsDocument,
|
||
variables: { modelId },
|
||
});
|
||
|
||
if (evo_equipments?.length) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectConfiguration'],
|
||
});
|
||
}
|
||
}
|
||
|
||
if (!leaseObjectUseFor) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectLeaseObjectUseFor'],
|
||
});
|
||
}
|
||
|
||
if (leaseObjectTypeId) {
|
||
const {
|
||
data: { evo_leasingobject_type },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetLeaseObjectTypeDocument,
|
||
variables: {
|
||
leaseObjectTypeId,
|
||
},
|
||
});
|
||
|
||
if (modelId) {
|
||
const {
|
||
data: { evo_model },
|
||
} = await apolloClient.query({
|
||
query: CRMTypes.GetModelDocument,
|
||
variables: {
|
||
modelId,
|
||
},
|
||
});
|
||
|
||
const isNotTrailer =
|
||
evo_leasingobject_type?.evo_id !== null &&
|
||
evo_leasingobject_type?.evo_id !== '8' &&
|
||
evo_model?.evo_trailer_sign !== true;
|
||
|
||
if (isNotTrailer && engineType !== 100_000_003 && engineVolume <= 0) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['tbxEngineVolume'],
|
||
});
|
||
}
|
||
|
||
if (isNotTrailer && !engineType) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectEngineType'],
|
||
});
|
||
}
|
||
|
||
if (isNotTrailer && leaseObjectMotorPower <= 0) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['tbxLeaseObjectMotorPower'],
|
||
});
|
||
}
|
||
}
|
||
|
||
if (evo_leasingobject_type?.evo_id === '1' && countSeats >= 9) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Количество мест должно быть меньше 9',
|
||
path: ['tbxCountSeats'],
|
||
});
|
||
}
|
||
|
||
if (
|
||
(evo_leasingobject_type?.evo_id === '4' || evo_leasingobject_type?.evo_id === '5') &&
|
||
countSeats <= 8
|
||
) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Количество мест должно быть больше 8',
|
||
path: ['tbxCountSeats'],
|
||
});
|
||
}
|
||
|
||
if (evo_leasingobject_type?.evo_id === '2' && maxMass <= 0) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['tbxMaxMass'],
|
||
});
|
||
}
|
||
|
||
if (
|
||
!leaseObjectCategory &&
|
||
Boolean(
|
||
evo_leasingobject_type?.evo_id &&
|
||
!['6', '9', '10'].includes(evo_leasingobject_type?.evo_id)
|
||
)
|
||
) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['selectLeaseObjectCategory'],
|
||
});
|
||
}
|
||
|
||
if (
|
||
evo_leasingobject_type?.evo_id &&
|
||
['6', '9', '10'].includes(evo_leasingobject_type?.evo_id) &&
|
||
!maxSpeed
|
||
) {
|
||
ctx.addIssue({
|
||
code: z.ZodIssueCode.custom,
|
||
message: 'Не заполнено поле',
|
||
path: ['tbxMaxSpeed'],
|
||
});
|
||
}
|
||
}
|
||
}
|
||
);
|
||
}
|