feat(SW-1012): Added possibility for multiple include params for hotels
This commit is contained in:
committed by
Fredrik Thorsson
parent
92bbfcf533
commit
05006506f0
@@ -4,15 +4,21 @@ import { ChildBedTypeEnum, type PaymentMethodEnum } from "@/constants/booking"
|
||||
import { dt } from "@/lib/dt"
|
||||
import { toLang } from "@/server/utils"
|
||||
|
||||
import { imageMetaDataSchema, imageSizesSchema } from "./schemas/image"
|
||||
import {
|
||||
imageMetaDataSchema,
|
||||
imageSchema,
|
||||
imageSizesSchema,
|
||||
} from "./schemas/image"
|
||||
import { restaurantSchema } from "./schemas/restaurants"
|
||||
import { roomSchema } from "./schemas/room"
|
||||
import { specialAlertsSchema } from "./schemas/specialAlerts"
|
||||
import { getPoiGroupByCategoryName } from "./utils"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import { FacilityEnum } from "@/types/enums/facilities"
|
||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||
import { RestaurantData, RoomData } from "@/types/hotel"
|
||||
|
||||
const ratingsSchema = z
|
||||
.object({
|
||||
@@ -159,11 +165,6 @@ export const facilitySchema = z.object({
|
||||
),
|
||||
})
|
||||
|
||||
export const imageSchema = z.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
|
||||
export const gallerySchema = z.object({
|
||||
heroImages: z.array(imageSchema),
|
||||
smallerImages: z.array(imageSchema),
|
||||
@@ -332,36 +333,6 @@ const socialMediaSchema = z.object({
|
||||
facebook: z.string().optional(),
|
||||
})
|
||||
|
||||
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(),
|
||||
})
|
||||
|
||||
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([])
|
||||
|
||||
const relationshipsSchema = z.object({
|
||||
restaurants: z.object({
|
||||
links: z.object({
|
||||
@@ -487,6 +458,19 @@ export const hotelAttributesSchema = z.object({
|
||||
specialNeedGroups: z.array(specialNeedGroupSchema),
|
||||
})
|
||||
|
||||
const includedSchema = z
|
||||
.array(z.union([roomSchema, restaurantSchema]))
|
||||
.transform((data) => {
|
||||
const rooms = data.filter((d) => d.type === "roomcategories") as RoomData[]
|
||||
const restaurants = data.filter(
|
||||
(d) => d.type === "restaurants"
|
||||
) as RestaurantData[]
|
||||
return {
|
||||
rooms,
|
||||
restaurants,
|
||||
}
|
||||
})
|
||||
|
||||
// NOTE: Find schema at: https://aks-test.scandichotels.com/hotel/swagger/v1/index.html
|
||||
export const getHotelDataSchema = z.object({
|
||||
data: z.object({
|
||||
@@ -504,7 +488,7 @@ 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: z.array(roomSchema).optional(),
|
||||
included: includedSchema.optional(),
|
||||
})
|
||||
|
||||
export const childrenSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user