From 3087bd918b8c1cb56ca91fe254966df9bbc54931 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Thu, 19 Dec 2024 09:21:33 +0100 Subject: [PATCH] fix(SW-1211): Fixed issue where special alerts are showing when either startDate or endDate is missing --- server/routers/hotels/schemas/specialAlerts.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/routers/hotels/schemas/specialAlerts.ts b/server/routers/hotels/schemas/specialAlerts.ts index 9d5dbd63c..6acd8407a 100644 --- a/server/routers/hotels/schemas/specialAlerts.ts +++ b/server/routers/hotels/schemas/specialAlerts.ts @@ -1,7 +1,9 @@ -import { dt } from "@/lib/dt" -import { AlertTypeEnum } from "@/types/enums/alert" import { z } from "zod" +import { dt } from "@/lib/dt" + +import { AlertTypeEnum } from "@/types/enums/alert" + const specialAlertSchema = z.object({ type: z.string(), title: z.string().optional(), @@ -16,10 +18,14 @@ export const specialAlertsSchema = z .transform((data) => { const now = dt().utc().format("YYYY-MM-DD") const filteredAlerts = data.filter((alert) => { - const shouldShowNow = - alert.startDate && alert.endDate - ? alert.startDate <= now && alert.endDate >= now - : true + let shouldShowNow = true + + if (alert.startDate && alert.startDate > now) { + shouldShowNow = false + } + if (alert.endDate && alert.endDate < now) { + shouldShowNow = false + } const hasText = alert.description || alert.title return shouldShowNow && hasText })