Merged in feat/SW-1333-hotel-endpoint (pull request #1206)
Feat(SW-133): Add additionalData endpoint Approved-by: Erik Tiekstra Approved-by: Fredrik Thorsson
This commit is contained in:
@@ -3,6 +3,7 @@ import { z } from "zod"
|
||||
import { ChildBedTypeEnum, type PaymentMethodEnum } from "@/constants/booking"
|
||||
import { toLang } from "@/server/utils"
|
||||
|
||||
import { additionalDataSchema } from "./schemas/additionalData"
|
||||
import { imageSchema } from "./schemas/image"
|
||||
import { restaurantSchema } from "./schemas/restaurants"
|
||||
import { roomSchema } from "./schemas/room"
|
||||
@@ -12,7 +13,7 @@ import { getPoiGroupByCategoryName } from "./utils"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { FacilityEnum } from "@/types/enums/facilities"
|
||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||
import type { RestaurantData, RoomData } from "@/types/hotel"
|
||||
import type { AdditionalData, RestaurantData, RoomData } from "@/types/hotel"
|
||||
|
||||
const ratingsSchema = z
|
||||
.object({
|
||||
@@ -119,7 +120,7 @@ const hotelContentSchema = z.object({
|
||||
restaurantsOverviewPageLink: z.string().optional(),
|
||||
restaurantsContentDescriptionShort: z.string().optional(),
|
||||
restaurantsContentDescriptionMedium: z.string().optional(),
|
||||
}),
|
||||
}), // TODO remove, use new /additionalData endpoint
|
||||
})
|
||||
|
||||
const detailedFacilitySchema = z.object({
|
||||
@@ -134,12 +135,12 @@ const detailedFacilitySchema = z.object({
|
||||
export const facilitySchema = z.object({
|
||||
headingText: z.string().default(""),
|
||||
heroImages: z.array(imageSchema),
|
||||
})
|
||||
}) // TODO remove, use new /additionalData endpoint
|
||||
|
||||
export const gallerySchema = z.object({
|
||||
heroImages: z.array(imageSchema),
|
||||
smallerImages: z.array(imageSchema),
|
||||
})
|
||||
}) // TODO remove, use new /additionalData endpoint
|
||||
|
||||
const healthFacilitySchema = z.object({
|
||||
type: z.string(),
|
||||
@@ -289,16 +290,6 @@ export const parkingSchema = z.object({
|
||||
pricing: parkingPricingSchema,
|
||||
})
|
||||
|
||||
const specialNeedSchema = z.object({
|
||||
name: z.string(),
|
||||
details: z.string(),
|
||||
})
|
||||
|
||||
const specialNeedGroupSchema = z.object({
|
||||
name: z.string(),
|
||||
specialNeeds: z.array(specialNeedSchema),
|
||||
})
|
||||
|
||||
const socialMediaSchema = z.object({
|
||||
instagram: z.string().optional(),
|
||||
facebook: z.string().optional(),
|
||||
@@ -392,11 +383,10 @@ type DetailedFacility = { id: FacilityEnum } & z.infer<
|
||||
typeof detailedFacilitySchema
|
||||
>
|
||||
export const hotelAttributesSchema = z.object({
|
||||
accessibilityElevatorPitchText: z.string().optional(),
|
||||
address: addressSchema,
|
||||
cityId: z.string(),
|
||||
cityName: z.string(),
|
||||
conferencesAndMeetings: facilitySchema.optional(),
|
||||
conferencesAndMeetings: facilitySchema.optional(), // TODO remove, use new /additionalData endpoint
|
||||
contactInformation: contactInformationSchema,
|
||||
detailedFacilities: z.array(detailedFacilitySchema).transform(
|
||||
(facilities) =>
|
||||
@@ -407,13 +397,11 @@ export const hotelAttributesSchema = z.object({
|
||||
)
|
||||
.sort((a, b) => b.sortOrder - a.sortOrder) as DetailedFacility[]
|
||||
),
|
||||
gallery: gallerySchema.optional(),
|
||||
gallery: gallerySchema.optional(), // TODO remove, use new /additionalData endpoint
|
||||
galleryImages: z.array(imageSchema).optional(),
|
||||
healthAndWellness: facilitySchema.optional(),
|
||||
healthFacilities: z.array(healthFacilitySchema),
|
||||
hotelContent: hotelContentSchema,
|
||||
hotelFacts: hotelFactsSchema,
|
||||
hotelRoomElevatorPitchText: z.string().optional(),
|
||||
hotelType: z.string().optional(),
|
||||
isActive: z.boolean(),
|
||||
isPublished: z.boolean(),
|
||||
@@ -430,23 +418,26 @@ export const hotelAttributesSchema = z.object({
|
||||
),
|
||||
ratings: ratingsSchema,
|
||||
rewardNight: rewardNightSchema,
|
||||
restaurantImages: facilitySchema.optional(),
|
||||
restaurantImages: facilitySchema.optional(), // TODO remove, use new /additionalData endpoint
|
||||
socialMedia: socialMediaSchema,
|
||||
specialAlerts: specialAlertsSchema,
|
||||
specialNeedGroups: z.array(specialNeedGroupSchema),
|
||||
vat: z.number(),
|
||||
})
|
||||
|
||||
const includedSchema = z
|
||||
.array(z.union([roomSchema, restaurantSchema]))
|
||||
.array(z.union([roomSchema, restaurantSchema, additionalDataSchema]))
|
||||
.transform((data) => {
|
||||
const rooms = data.filter((d) => d.type === "roomcategories") as RoomData[]
|
||||
const restaurants = data.filter(
|
||||
(d) => d.type === "restaurants"
|
||||
) as RestaurantData[]
|
||||
const additionalData = data.filter(
|
||||
(d) => d.type === "additionalData"
|
||||
) as AdditionalData[]
|
||||
return {
|
||||
rooms,
|
||||
restaurants,
|
||||
additionalData,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -467,7 +458,13 @@ export const getHotelDataSchema = z.object({
|
||||
}),
|
||||
// NOTE: We can pass an "include" param to the hotel API to retrieve
|
||||
// additional data for an individual hotel.
|
||||
included: includedSchema.optional(),
|
||||
included: includedSchema.optional().transform((incl) => {
|
||||
return {
|
||||
restaurants: incl?.restaurants,
|
||||
rooms: incl?.rooms,
|
||||
additionalData: incl?.additionalData[0],
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const childrenSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user