28 lines
652 B
TypeScript
28 lines
652 B
TypeScript
import type { RoomData } from "@/types/hotel"
|
|
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
|
|
|
export function getBookedHotelRoom(
|
|
rooms: RoomData[] | undefined,
|
|
roomTypeCode: BookingConfirmation["booking"]["roomTypeCode"]
|
|
) {
|
|
if (!rooms?.length || !roomTypeCode) {
|
|
return null
|
|
}
|
|
const room = rooms?.find((r) => {
|
|
return r.roomTypes.find((roomType) => roomType.code === roomTypeCode)
|
|
})
|
|
if (!room) {
|
|
return null
|
|
}
|
|
const bedType = room.roomTypes.find(
|
|
(roomType) => roomType.code === roomTypeCode
|
|
)
|
|
if (!bedType) {
|
|
return null
|
|
}
|
|
return {
|
|
...room,
|
|
bedType,
|
|
}
|
|
}
|