Feat(SW-133): Add additionalData endpoint Approved-by: Erik Tiekstra Approved-by: Fredrik Thorsson
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { imageSchema } from "./image"
|
|
import { specialAlertsSchema } from "./specialAlerts"
|
|
|
|
const restaurantPriceSchema = z.object({
|
|
currency: z.string(),
|
|
amount: z.number(),
|
|
})
|
|
export const restaurantDaySchema = z.object({
|
|
sortOrder: z.number(),
|
|
alwaysOpen: z.boolean(),
|
|
isClosed: z.boolean(),
|
|
openingTime: z.string(),
|
|
closingTime: z.string(),
|
|
})
|
|
export const restaurantOpeningHoursSchema = z.object({
|
|
isActive: z.boolean(),
|
|
name: 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(),
|
|
isPublished: z.boolean().default(false),
|
|
restaurantPage: z.boolean(),
|
|
email: z.string().optional(),
|
|
phoneNumber: z.string().optional(),
|
|
externalBreakfast: z
|
|
.object({
|
|
isAvailable: z.boolean(),
|
|
localPriceForExternalGuests: restaurantPriceSchema.optional(),
|
|
requestedPriceForExternalGuests: restaurantPriceSchema.optional(),
|
|
})
|
|
.optional(),
|
|
menus: z
|
|
.array(
|
|
z.object({
|
|
name: z.string(),
|
|
url: z.string(),
|
|
})
|
|
)
|
|
.default([]),
|
|
openingDetails: z.array(restaurantOpeningDetailSchema).default([]),
|
|
content: z.object({
|
|
images: z.array(imageSchema),
|
|
texts: z.object({
|
|
descriptions: z.object({
|
|
short: z.string().default(""),
|
|
medium: z.string().default(""),
|
|
}),
|
|
}),
|
|
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)
|
|
})
|