Files
web/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts
Bianca Widstam dc18589afe Merged in fix/isostring-error (pull request #3386)
fix: isostring

* fix: isostring


Approved-by: Joakim Jäderberg
2026-01-05 09:21:30 +00:00

36 lines
1.3 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: alert.endDate ? dt.utc(alert.endDate).toISOString() : null,
startDate: alert.startDate ? dt.utc(alert.startDate).toISOString() : null,
}))
)