feat: SW-1356 Reward night bookingflow * feat: SW-1356 Reward night bookingflow * feat: SW-1356 Removed extra param booking call * feat: SW-1356 Optimized as review comments * feat: SW-1356 Schema validation updates * feat: SW-1356 Fix after rebase * feat: SW-1356 Optimised price.redemptions check * feat: SW-1356 Updated Props naming Approved-by: Arvid Norlin
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { productSchema } from "./product"
|
|
|
|
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
|
|
export const roomConfigurationSchema = z
|
|
.object({
|
|
breakfastIncludedInAllRatesMember: z.boolean().default(false),
|
|
breakfastIncludedInAllRatesPublic: z.boolean().default(false),
|
|
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(),
|
|
status: z.string(),
|
|
})
|
|
.transform((data) => {
|
|
if (data.products.length) {
|
|
if (data.products[0].redemptions) {
|
|
// No need of rate check in reward night scenario
|
|
return { ...data }
|
|
} else {
|
|
/**
|
|
* Just guaranteeing that if all products all miss
|
|
* both public and member rateCode that status is
|
|
* set to `NotAvailable`
|
|
*/
|
|
const allProductsMissBothRateCodes = data.products.every(
|
|
(product) => !product.public?.rateCode && !product.member?.rateCode
|
|
)
|
|
if (allProductsMissBothRateCodes) {
|
|
return {
|
|
...data,
|
|
status: AvailabilityEnum.NotAvailable,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return data
|
|
})
|