fix: cache hotel response
This commit is contained in:
@@ -9,5 +9,5 @@ export const childrenSchema = z.object({
|
||||
|
||||
export const occupancySchema = z.object({
|
||||
adults: z.number(),
|
||||
children: z.array(childrenSchema),
|
||||
children: z.array(childrenSchema).default([]),
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { nullableNumberValidator } from "@/utils/zod/numberValidator"
|
||||
|
||||
import { addressSchema } from "./hotel/address"
|
||||
import { contactInformationSchema } from "./hotel/contactInformation"
|
||||
import { hotelContentSchema } from "./hotel/content"
|
||||
@@ -17,8 +19,8 @@ import { rewardNightSchema } from "./hotel/rewardNight"
|
||||
import { socialMediaSchema } from "./hotel/socialMedia"
|
||||
import { specialAlertsSchema } from "./hotel/specialAlerts"
|
||||
import { specialNeedGroupSchema } from "./hotel/specialNeedGroups"
|
||||
import { imageSchema } from "./image"
|
||||
import { facilitySchema } from "./additionalData"
|
||||
import { imageSchema } from "./image"
|
||||
|
||||
export const attributesSchema = z.object({
|
||||
accessibilityElevatorPitchText: z.string().optional(),
|
||||
@@ -51,13 +53,23 @@ export const attributesSchema = z.object({
|
||||
socialMedia: socialMediaSchema,
|
||||
specialAlerts: specialAlertsSchema,
|
||||
specialNeedGroups: z.array(specialNeedGroupSchema),
|
||||
vat: z.number(),
|
||||
vat: nullableNumberValidator,
|
||||
})
|
||||
|
||||
export const includesSchema = z
|
||||
export const includedSchema = z
|
||||
.array(includeSchema)
|
||||
.default([])
|
||||
.transform((data) => data.filter((item) => !!item))
|
||||
.transform((data) =>
|
||||
data.filter((item) => {
|
||||
if (item) {
|
||||
if ("isPublished" in item && item.isPublished === false) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
)
|
||||
|
||||
const relationshipSchema = z.object({
|
||||
links: z.object({
|
||||
|
||||
@@ -2,70 +2,92 @@ import { z } from "zod"
|
||||
|
||||
import { imageSchema } from "@/server/routers/hotels/schemas/image"
|
||||
|
||||
import {
|
||||
nullableIntValidator,
|
||||
nullableNumberValidator,
|
||||
} from "@/utils/zod/numberValidator"
|
||||
import {
|
||||
nullableStringUrlValidator,
|
||||
nullableStringValidator,
|
||||
} from "@/utils/zod/stringValidator"
|
||||
|
||||
import { specialAlertsSchema } from "../specialAlerts"
|
||||
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
|
||||
const descriptionSchema = z.object({
|
||||
medium: nullableStringValidator,
|
||||
short: nullableStringValidator,
|
||||
})
|
||||
|
||||
const textSchema = z.object({
|
||||
descriptions: descriptionSchema,
|
||||
facilityInformation: nullableStringValidator,
|
||||
meetingDescription: descriptionSchema.optional(),
|
||||
surroundingInformation: nullableStringValidator,
|
||||
})
|
||||
|
||||
const contentSchema = z.object({
|
||||
images: z.array(imageSchema).default([]),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
medium: z.string().default(""),
|
||||
short: z.string().default(""),
|
||||
}),
|
||||
}),
|
||||
texts: textSchema,
|
||||
})
|
||||
|
||||
const restaurantPriceSchema = z.object({
|
||||
amount: nullableNumberValidator,
|
||||
currency: z.nativeEnum(CurrencyEnum).default(CurrencyEnum.SEK),
|
||||
})
|
||||
|
||||
const externalBreakfastSchema = z.object({
|
||||
isAvailable: z.boolean().default(false),
|
||||
localPriceForExternalGuests: z.object({
|
||||
amount: z.number().default(0),
|
||||
currency: z.nativeEnum(CurrencyEnum).default(CurrencyEnum.SEK),
|
||||
}),
|
||||
localPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
requestedPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
})
|
||||
|
||||
const menuItemSchema = z.object({
|
||||
name: z.string(),
|
||||
url: z.string().url(),
|
||||
name: nullableStringValidator,
|
||||
url: nullableStringUrlValidator,
|
||||
})
|
||||
|
||||
const daySchema = z.object({
|
||||
export const openingHoursDetailsSchema = z.object({
|
||||
alwaysOpen: z.boolean().default(false),
|
||||
closingTime: z.string().default(""),
|
||||
closingTime: nullableStringValidator,
|
||||
isClosed: z.boolean().default(false),
|
||||
openingTime: z.string().default(""),
|
||||
sortOrder: z.number().int().default(0),
|
||||
openingTime: nullableStringValidator,
|
||||
sortOrder: nullableIntValidator,
|
||||
})
|
||||
|
||||
export const openingHoursSchema = z.object({
|
||||
friday: openingHoursDetailsSchema.optional(),
|
||||
isActive: z.boolean().default(false),
|
||||
monday: openingHoursDetailsSchema.optional(),
|
||||
name: nullableStringValidator,
|
||||
saturday: openingHoursDetailsSchema.optional(),
|
||||
sunday: openingHoursDetailsSchema.optional(),
|
||||
thursday: openingHoursDetailsSchema.optional(),
|
||||
tuesday: openingHoursDetailsSchema.optional(),
|
||||
wednesday: openingHoursDetailsSchema.optional(),
|
||||
})
|
||||
|
||||
const openingDetailsSchema = z.object({
|
||||
alternateOpeningHours: z.object({
|
||||
isActive: z.boolean().default(false),
|
||||
}),
|
||||
openingHours: z.object({
|
||||
friday: daySchema,
|
||||
isActive: z.boolean().default(false),
|
||||
monday: daySchema,
|
||||
name: z.string().default(""),
|
||||
saturday: daySchema,
|
||||
sunday: daySchema,
|
||||
thursday: daySchema,
|
||||
tuesday: daySchema,
|
||||
wednesday: daySchema,
|
||||
}),
|
||||
alternateOpeningHours: openingHoursSchema.optional(),
|
||||
openingHours: openingHoursSchema,
|
||||
ordinary: openingHoursSchema.optional(),
|
||||
weekends: openingHoursSchema.optional(),
|
||||
})
|
||||
|
||||
export const restaurantsSchema = z.object({
|
||||
attributes: z.object({
|
||||
bookTableUrl: z.string().default(""),
|
||||
bookTableUrl: nullableStringValidator,
|
||||
content: contentSchema,
|
||||
// When using .email().default("") is not sufficent
|
||||
// so .optional also needs to be chained
|
||||
email: z.string().email().optional(),
|
||||
externalBreakfast: externalBreakfastSchema,
|
||||
isPublished: z.boolean().default(false),
|
||||
menus: z.array(menuItemSchema).default([]),
|
||||
name: z.string().default(""),
|
||||
openingDetails: z.array(openingDetailsSchema).default([]),
|
||||
phoneNumber: z.string().optional(),
|
||||
restaurantPage: z.boolean().default(false),
|
||||
specialAlerts: z.array(z.object({})).default([]),
|
||||
specialAlerts: specialAlertsSchema,
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.literal("restaurants"),
|
||||
|
||||
@@ -2,15 +2,17 @@ import { z } from "zod"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import { nullableStringValidator } from "@/utils/zod/stringValidator"
|
||||
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
description: z.string().optional(),
|
||||
displayInBookingFlow: z.boolean(),
|
||||
endDate: z.string().optional(),
|
||||
startDate: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
type: z.string(),
|
||||
description: nullableStringValidator,
|
||||
displayInBookingFlow: z.boolean().default(false),
|
||||
endDate: nullableStringValidator,
|
||||
startDate: nullableStringValidator,
|
||||
title: nullableStringValidator,
|
||||
type: nullableStringValidator,
|
||||
})
|
||||
|
||||
export const specialAlertsSchema = z
|
||||
|
||||
@@ -5,17 +5,19 @@ import { productSchema } from "./product"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
|
||||
export const roomConfigurationSchema = z.object({
|
||||
features: z.array(
|
||||
z.object({
|
||||
inventory: z.number(),
|
||||
code: z.enum([
|
||||
RoomPackageCodeEnum.PET_ROOM,
|
||||
RoomPackageCodeEnum.ALLERGY_ROOM,
|
||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||
]),
|
||||
})
|
||||
),
|
||||
products: z.array(productSchema),
|
||||
features: z
|
||||
.array(
|
||||
z.object({
|
||||
inventory: z.number(),
|
||||
code: z.enum([
|
||||
RoomPackageCodeEnum.PET_ROOM,
|
||||
RoomPackageCodeEnum.ALLERGY_ROOM,
|
||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||
]),
|
||||
})
|
||||
)
|
||||
.default([]),
|
||||
products: z.array(productSchema).default([]),
|
||||
roomsLeft: z.number(),
|
||||
roomType: z.string(),
|
||||
roomTypeCode: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user