feat(SW-1012): Added possibility for multiple include params for hotels
This commit is contained in:
committed by
Fredrik Thorsson
parent
92bbfcf533
commit
05006506f0
@@ -13,3 +13,8 @@ export const imageMetaDataSchema = z.object({
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
})
|
||||
|
||||
export const imageSchema = z.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
|
||||
80
server/routers/hotels/schemas/restaurants.ts
Normal file
80
server/routers/hotels/schemas/restaurants.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { imageSchema } from "./image"
|
||||
import { specialAlertsSchema } from "./specialAlerts"
|
||||
|
||||
const restaurantPriceSchema = z.object({
|
||||
currency: z.string(),
|
||||
amount: z.number(),
|
||||
})
|
||||
const restaurantDaySchema = z.object({
|
||||
sortOrder: z.number(),
|
||||
alwaysOpen: z.boolean(),
|
||||
isClosed: z.boolean(),
|
||||
openingTime: z.string(),
|
||||
closingTime: z.string(),
|
||||
})
|
||||
const restaurantOpeningHoursSchema = z.object({
|
||||
isActive: z.boolean(),
|
||||
name: z.string().optional(),
|
||||
openingTime: z.string().optional(),
|
||||
closingTime: z.string().optional(),
|
||||
monday: restaurantDaySchema.optional(),
|
||||
tuesday: restaurantDaySchema.optional(),
|
||||
wednesday: restaurantDaySchema.optional(),
|
||||
thursday: restaurantDaySchema.optional(),
|
||||
friday: restaurantDaySchema.optional(),
|
||||
saturday: restaurantDaySchema.optional(),
|
||||
sunday: restaurantDaySchema.optional(),
|
||||
})
|
||||
|
||||
const restaurantOpeningDetailSchema = z.object({
|
||||
openingHours: restaurantOpeningHoursSchema,
|
||||
alternateOpeningHours: restaurantOpeningHoursSchema.optional(),
|
||||
})
|
||||
|
||||
export const restaurantSchema = z
|
||||
.object({
|
||||
attributes: z.object({
|
||||
name: z.string().optional(),
|
||||
isPublished: z.boolean(),
|
||||
email: z.string().optional(),
|
||||
phoneNumber: z.string().optional(),
|
||||
externalBreakfast: z.object({
|
||||
isAvailable: z.boolean(),
|
||||
localPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
requestedPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
}),
|
||||
menus: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
url: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
openingDetails: z.array(restaurantOpeningDetailSchema),
|
||||
content: z.object({
|
||||
images: z.array(imageSchema),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
short: z.string(),
|
||||
medium: z.string(),
|
||||
}),
|
||||
}),
|
||||
bookTableUrl: z.string().optional(),
|
||||
specialAlerts: specialAlertsSchema,
|
||||
}),
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.literal("restaurants"),
|
||||
})
|
||||
.transform(({ attributes, id, type }) => ({ ...attributes, id, type }))
|
||||
|
||||
export const getRestaurantsSchema = z
|
||||
.object({
|
||||
data: z.array(restaurantSchema),
|
||||
})
|
||||
.transform(({ data }) => {
|
||||
return data.filter((item) => !!item.isPublished)
|
||||
})
|
||||
@@ -78,7 +78,7 @@ export const roomSchema = z
|
||||
}),
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.enum(["roomcategories"]),
|
||||
type: z.literal("roomcategories"),
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
|
||||
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