Files
web/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts
2025-12-05 06:31:17 +00:00

35 lines
1.1 KiB
TypeScript

import { z } from "zod"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
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: alert.endDate,
startDate: alert.startDate,
}))
)