chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import type { RouterOutput } from "@scandic-hotels/trpc/client"
|
|
|
|
import type { AvailabilityWithRoomInfo, RoomPackage } from "./types"
|
|
|
|
type RoomConfiguration = Extract<
|
|
RouterOutput["hotel"]["availability"]["selectRate"]["rooms"][number],
|
|
{ roomConfigurations: unknown }
|
|
>["roomConfigurations"][number]
|
|
type RoomCategory = NonNullable<
|
|
RouterOutput["hotel"]["get"]
|
|
>["roomCategories"][number]
|
|
|
|
export function includeRoomInfo({
|
|
roomConfigurations,
|
|
roomCategories,
|
|
selectedPackages,
|
|
}: {
|
|
roomConfigurations: RoomConfiguration[]
|
|
roomCategories: RoomCategory[]
|
|
selectedPackages: RoomPackage[]
|
|
}): (AvailabilityWithRoomInfo | null)[] {
|
|
return roomConfigurations.map((roomConfiguration) => {
|
|
const room = roomCategories.find((roomCategory) =>
|
|
roomCategory.roomTypes.find(
|
|
(roomType) => roomType.code === roomConfiguration.roomTypeCode
|
|
)
|
|
)
|
|
|
|
if (!room) {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
...roomConfiguration,
|
|
roomInfo: room,
|
|
selectedPackages,
|
|
} satisfies AvailabilityWithRoomInfo
|
|
})
|
|
}
|