feat(SW-508): contract changes for hotel alerts

This commit is contained in:
Erik Tiekstra
2024-11-07 13:52:22 +01:00
parent 52ae49246f
commit de5d80ec92
3 changed files with 25 additions and 24 deletions

View File

@@ -312,34 +312,35 @@ const socialMediaSchema = z.object({
facebook: z.string().optional(),
})
const metaSpecialAlertSchema = z.object({
const specialAlertSchema = z.object({
type: z.string(),
title: z.string().optional(),
description: z.string().optional(),
displayInBookingFlow: z.boolean(),
startDate: z.string(),
endDate: z.string(),
startDate: z.string().optional(),
endDate: z.string().optional(),
})
const metaSchema = z.object({
specialAlerts: z
.array(metaSpecialAlertSchema)
.transform((data) => {
const now = dt().utc().format("YYYY-MM-DD")
const filteredAlerts = data.filter((alert) => {
const shouldShowNow = alert.startDate <= now && alert.endDate >= now
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,
}))
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
})
.default([]),
})
return filteredAlerts.map((alert, idx) => ({
id: `alert-${alert.type}-${idx}`,
type: AlertTypeEnum.Info,
heading: alert.title || null,
text: alert.description || null,
}))
})
.default([])
const relationshipsSchema = z.object({
restaurants: z.object({
@@ -425,7 +426,7 @@ export const getHotelDataSchema = z.object({
parking: z.array(parkingSchema),
specialNeedGroups: z.array(specialNeedGroupSchema),
socialMedia: socialMediaSchema,
meta: metaSchema.optional(),
specialAlerts: specialAlertsSchema,
isActive: z.boolean(),
conferencesAndMeetings: facilitySchema.optional(),
healthAndWellness: facilitySchema.optional(),

View File

@@ -294,7 +294,7 @@ export const hotelQueryRouter = router({
const hotelAttributes = hotelData.data.attributes
const images = hotelAttributes.gallery?.smallerImages
const hotelAlerts = hotelAttributes.meta?.specialAlerts || []
const hotelAlerts = hotelAttributes.specialAlerts
const roomCategories = included
? included.filter((item) => item.type === "roomcategories")