Files
web/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts
Bianca Widstam 57d0e1b27b Merged in fix/BOOK-662-handle-overlapping-dates-timezone (pull request #3319)
Fix/BOOK-662 handle overlapping dates timezone

* fix(BOOK-662): handle overlapping dates alerts

* fix(BOOK-662): handle overlapping dates alerts

* fix(BOOK-662): add test same dates


Approved-by: Anton Gunnarsson
2025-12-19 14:03:30 +00:00

36 lines
1.2 KiB
TypeScript

import { z } from "zod"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { dt } from "@scandic-hotels/common/dt"
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
const specialAlertSchema = z.object({
description: nullableStringValidator,
displayInBookingFlow: z.boolean().default(false),
endDate: nullableStringValidator,
startDate: nullableStringValidator,
title: nullableStringValidator,
type: nullableStringValidator,
})
export const specialAlertsSchema = z
.array(specialAlertSchema)
.nullish()
// Filter out alerts with no title and no description since they won't have any visible content
// We're filtering on dates on the hotel page itself
.transform((arr) =>
arr ? arr.filter((alert) => alert?.description || alert?.title) : []
)
.transform((alerts) =>
alerts.map((alert, idx) => ({
heading: alert.title || null,
id: `alert-${alert.type}-${idx}`,
name: alert.type,
text: alert.description || null,
type: AlertTypeEnum.Info,
displayInBookingFlow: alert.displayInBookingFlow,
endDate: dt.utc(alert.endDate).toISOString(),
startDate: dt.utc(alert.startDate).toISOString(),
}))
)