feat(SW-1012): Added possibility for multiple include params for hotels
This commit is contained in:
committed by
Fredrik Thorsson
parent
92bbfcf533
commit
05006506f0
33
server/routers/hotels/schemas/specialAlerts.ts
Normal file
33
server/routers/hotels/schemas/specialAlerts.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { dt } from "@/lib/dt"
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
import { z } from "zod"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
type: z.string(),
|
||||
title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
displayInBookingFlow: z.boolean(),
|
||||
startDate: z.string().optional(),
|
||||
endDate: z.string().optional(),
|
||||
})
|
||||
|
||||
export const specialAlertsSchema = z
|
||||
.array(specialAlertSchema)
|
||||
.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
|
||||
const hasText = alert.description || alert.title
|
||||
return shouldShowNow && hasText
|
||||
})
|
||||
return filteredAlerts.map((alert, idx) => ({
|
||||
id: `alert-${alert.type}-${idx}`,
|
||||
type: AlertTypeEnum.Info,
|
||||
heading: alert.title || null,
|
||||
text: alert.description || null,
|
||||
}))
|
||||
})
|
||||
.default([])
|
||||
Reference in New Issue
Block a user