From 01c2c7bab694c84e474c8917c1be27002a4caed2 Mon Sep 17 00:00:00 2001 From: Tomer Shvadron Date: Tue, 14 Jan 2025 17:40:31 +0200 Subject: [PATCH] refactor(report-schema): simplify isAlert field handling - Update isAlert to be a nullable boolean instead of a preprocessed value - Streamline schema validation for better clarity and usability (your code is so convoluted, even a GPS can't find its way through) --- apps/backoffice-v2/src/domains/business-reports/fetchers.ts | 4 +--- .../src/business-report/merchant-monitoring-client.ts | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/backoffice-v2/src/domains/business-reports/fetchers.ts b/apps/backoffice-v2/src/domains/business-reports/fetchers.ts index 0df62d03a4..39be1a3977 100644 --- a/apps/backoffice-v2/src/domains/business-reports/fetchers.ts +++ b/apps/backoffice-v2/src/domains/business-reports/fetchers.ts @@ -28,9 +28,7 @@ export const BusinessReportSchema = z parentCompanyName: z.string().nullable(), merchantId: z.string(), workflowVersion: z.enum([MERCHANT_REPORT_VERSIONS[0]!, ...MERCHANT_REPORT_VERSIONS.slice(1)]), - isAlert: z - .preprocess(value => (typeof value === 'string' ? JSON.parse(value) : value), z.boolean()) - .optional(), + isAlert: z.boolean().nullish(), companyName: z.string().nullish(), monitoringStatus: z.boolean(), website: z.object({ diff --git a/services/workflows-service/src/business-report/merchant-monitoring-client.ts b/services/workflows-service/src/business-report/merchant-monitoring-client.ts index c8731ba4ea..e8f2e1a3fe 100644 --- a/services/workflows-service/src/business-report/merchant-monitoring-client.ts +++ b/services/workflows-service/src/business-report/merchant-monitoring-client.ts @@ -13,6 +13,7 @@ import { import * as errors from '@/errors'; const CreateReportResponseSchema = z.object({}); + const ReportSchema = z.object({ id: z.string(), websiteId: z.string(), @@ -27,9 +28,7 @@ const ReportSchema = z.object({ }) .nullable(), riskScore: z.number().nullable(), - isAlert: z - .preprocess(value => (typeof value === 'string' ? JSON.parse(value) : value), z.boolean()) - .optional(), + isAlert: z.boolean().nullable(), companyName: z.string().nullish(), website: z.object({ id: z.string(),