process/insurance: validation
This commit is contained in:
parent
7fe8de83c8
commit
75aa3217b3
@ -544,3 +544,9 @@ query GetLeasingWithoutKaskoTypes($currentDate: DateTime) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetInsuranceCompany($accountId: Uuid!) {
|
||||
account(accountid: $accountId) {
|
||||
evo_osago_with_kasko
|
||||
}
|
||||
}
|
||||
|
||||
@ -451,6 +451,13 @@ export type GetLeasingWithoutKaskoTypesQueryVariables = Exact<{
|
||||
|
||||
export type GetLeasingWithoutKaskoTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_product_type: number | null, evo_min_period: number | null, evo_max_period: number | null, evo_min_price: number | null, evo_max_price: number | null, evo_visible_calc: boolean | null, evo_min_first_payment_perc: number | null, evo_max_first_payment_perc: number | null, evo_graph_price: number | null, label: string | null, value: string | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null, evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null> | null };
|
||||
|
||||
export type GetInsuranceCompanyQueryVariables = Exact<{
|
||||
accountId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetInsuranceCompanyQuery = { __typename?: 'Query', account: { __typename?: 'account', evo_osago_with_kasko: boolean | null } | null };
|
||||
|
||||
export type GetQuoteAddProductDataQueryVariables = Exact<{
|
||||
quoteId: Scalars['Uuid'];
|
||||
}>;
|
||||
@ -627,6 +634,7 @@ export const GetTelematicTypesDocument = {"kind":"Document","definitions":[{"kin
|
||||
export const GetTrackerTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTrackerTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000003"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CoreAddProductTypesFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CoreAddProductTypesFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"evo_addproduct_type"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]} as unknown as DocumentNode<GetTrackerTypesQuery, GetTrackerTypesQueryVariables>;
|
||||
export const GetInsNsibTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsNSIBTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000002"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CoreAddProductTypesFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CoreAddProductTypesFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"evo_addproduct_type"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]} as unknown as DocumentNode<GetInsNsibTypesQuery, GetInsNsibTypesQueryVariables>;
|
||||
export const GetLeasingWithoutKaskoTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeasingWithoutKaskoTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000007"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CoreAddProductTypesFields"}},{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_visible_calc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_first_payment_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_first_payment_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CoreAddProductTypesFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"evo_addproduct_type"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]} as unknown as DocumentNode<GetLeasingWithoutKaskoTypesQuery, GetLeasingWithoutKaskoTypesQueryVariables>;
|
||||
export const GetInsuranceCompanyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsuranceCompany"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"accountId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"account"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"accountid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"accountId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_osago_with_kasko"}}]}}]}}]} as unknown as DocumentNode<GetInsuranceCompanyQuery, GetInsuranceCompanyQueryVariables>;
|
||||
export const GetQuoteAddProductDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteAddProductData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode<GetQuoteAddProductDataQuery, GetQuoteAddProductDataQueryVariables>;
|
||||
export const GetQuoteBonusDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteBonusData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sale_bonus"}}]}}]}}]} as unknown as DocumentNode<GetQuoteBonusDataQuery, GetQuoteBonusDataQueryVariables>;
|
||||
export const GetQuoteConfiguratorDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteConfiguratorData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}}]}}]} as unknown as DocumentNode<GetQuoteConfiguratorDataQuery, GetQuoteConfiguratorDataQueryVariables>;
|
||||
|
||||
@ -129,6 +129,8 @@ export function validation(context: ProcessContext) {
|
||||
'leasingPeriod',
|
||||
'quote',
|
||||
'recalcWithRevision',
|
||||
'leasingWithoutKasko',
|
||||
'insDecentral',
|
||||
]);
|
||||
|
||||
return {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable zod/require-strict */
|
||||
import type { ValidationContext } from '../types';
|
||||
import type * as Insurance from '@/Components/Calculation/Form/Insurance/InsuranceTable/types';
|
||||
import { RowSchema } from '@/config/schema/insurance';
|
||||
@ -5,78 +6,115 @@ import ValuesSchema from '@/config/schema/values';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { z } from 'zod';
|
||||
|
||||
const InsuranceSchema = z.object({
|
||||
insurance: z.object({
|
||||
fingap: RowSchema,
|
||||
kasko: RowSchema,
|
||||
osago: RowSchema,
|
||||
}),
|
||||
});
|
||||
|
||||
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
return ValuesSchema.pick({
|
||||
insDecentral: true,
|
||||
leasingPeriod: true,
|
||||
leasingWithoutKasko: true,
|
||||
quote: true,
|
||||
recalcWithRevision: true,
|
||||
})
|
||||
.extend({
|
||||
insurance: z
|
||||
.object({
|
||||
fingap: RowSchema,
|
||||
kasko: RowSchema,
|
||||
osago: RowSchema,
|
||||
})
|
||||
.strict(),
|
||||
})
|
||||
.superRefine(async ({ leasingPeriod, recalcWithRevision, quote: quoteId, insurance }, ctx) => {
|
||||
if (quoteId) {
|
||||
const {
|
||||
data: { quote },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetQuoteDocument,
|
||||
variables: { quoteId },
|
||||
});
|
||||
if (
|
||||
recalcWithRevision &&
|
||||
quote?.evo_one_year_insurance === true &&
|
||||
leasingPeriod > 15 &&
|
||||
insurance.kasko.insTerm === 100_000_001
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
'Срок страхования КАСКО должен быть 12 месяцев, т.к. оформляется Однолетний полис',
|
||||
path: ['insurance'],
|
||||
.merge(InsuranceSchema)
|
||||
.superRefine(
|
||||
async (
|
||||
{
|
||||
leasingPeriod,
|
||||
recalcWithRevision,
|
||||
quote: quoteId,
|
||||
leasingWithoutKasko,
|
||||
insDecentral,
|
||||
insurance,
|
||||
},
|
||||
ctx
|
||||
) => {
|
||||
if (quoteId) {
|
||||
const {
|
||||
data: { quote },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetQuoteDocument,
|
||||
variables: { quoteId },
|
||||
});
|
||||
if (
|
||||
recalcWithRevision &&
|
||||
quote?.evo_one_year_insurance === true &&
|
||||
leasingPeriod > 15 &&
|
||||
insurance.kasko.insTerm === 100_000_001
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
'Срок страхования КАСКО должен быть 12 месяцев, т.к. оформляется Однолетний полис',
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
(['osago', 'kasko'] as Insurance.Keys[]).forEach((key) => {
|
||||
const { insCost, insured, policyType, insuranceCompany, insTerm } = insurance[key];
|
||||
|
||||
if (insured === 100_000_001 && insCost < 1000) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите стоимость ${policyType}, включаемую в график (>1000)`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insuranceCompany) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите страховую компанию ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insTerm) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите срок страхования ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insured) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите плательщика ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
!leasingWithoutKasko &&
|
||||
!insDecentral &&
|
||||
insurance.osago.insuranceCompany &&
|
||||
insurance.kasko.insuranceCompany !== insurance.osago.insuranceCompany
|
||||
) {
|
||||
const {
|
||||
data: { account },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetInsuranceCompanyDocument,
|
||||
variables: { accountId: insurance.osago.insuranceCompany },
|
||||
});
|
||||
|
||||
if (account?.evo_osago_with_kasko) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
'Невозможно страхование ОСАГО отдельно от КАСКО - страховая компания должна быть одна!',
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(['osago', 'kasko'] as Insurance.Keys[]).forEach((key) => {
|
||||
const { insCost, insured, policyType, insuranceCompany, insTerm } = insurance[key];
|
||||
|
||||
if (insCost === 0 && insured === 100_000_001) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите стоимость ${policyType}, включаемую в график`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insuranceCompany) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите страховую компанию ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insTerm) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите срок страхования ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
|
||||
if (insCost > 0 && !insured) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Укажите плательщика ${policyType}`,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user