diff --git a/apps/web/api/crm/types.ts b/apps/web/api/crm/types.ts index 4a8a47b..bc86dd9 100644 --- a/apps/web/api/crm/types.ts +++ b/apps/web/api/crm/types.ts @@ -21,7 +21,7 @@ export const RequestCreateKPSchema = z.object({ ), domainName: z.string(), finGAP: RiskSchema.array(), - insurance: RowSchema.array(), + insurance: RowSchema.extend({ key: z.string() }).array(), }); export type RequestCreateKP = z.infer; diff --git a/apps/web/server/routers/quote/index.ts b/apps/web/server/routers/quote/index.ts index 999260f..a6a6946 100644 --- a/apps/web/server/routers/quote/index.ts +++ b/apps/web/server/routers/quote/index.ts @@ -13,6 +13,7 @@ import { } from './types'; import { calculate } from '@/api/core/query'; import { createKP } from '@/api/crm/query'; +import type { RequestCreateKP } from '@/api/crm/types'; import type { User } from '@/api/user/types'; import initializeApollo from '@/apollo/client'; import defaultValues from '@/config/default-values'; @@ -133,7 +134,7 @@ export const quoteRouter = router({ }; } - const createKPResult = await createKP({ + const requestCreateKP = compatRequestCreateKP({ domainName: user.domainName, finGAP: input.fingap, insurance: Object.values(input.insurance.values), @@ -145,6 +146,8 @@ export const quoteRouter = router({ }, }); + const createKPResult = await createKP(requestCreateKP); + if (createKPResult.success === false) { return { success: false, @@ -171,6 +174,15 @@ export const quoteRouter = router({ }), }); +function compatRequestCreateKP(request: RequestCreateKP) { + const fingapIndex = request.insurance.findIndex((x) => x.key === 'fingap'); + if (fingapIndex >= 0) { + request.insurance[fingapIndex].key = 'finGAP'; + } + + return request; +} + async function compatValues( values: CalculationValues, { apolloClient }: Pick