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
27 lines
866 B
TypeScript
27 lines
866 B
TypeScript
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
|
|
|
|
import type { AvailabilityWithRoomInfo, SelectedRate } from "./types"
|
|
|
|
export function findUnavailableSelectedRooms({
|
|
selectedRates,
|
|
roomAvailabilityWithAdjustedRoomCount,
|
|
}: {
|
|
selectedRates: SelectedRate[]
|
|
roomAvailabilityWithAdjustedRoomCount: (AvailabilityWithRoomInfo | null)[][]
|
|
}): number[] {
|
|
const roomIndexesToDeselect: number[] = []
|
|
for (let roomIndex = selectedRates.length - 1; roomIndex >= 0; roomIndex--) {
|
|
const rate = selectedRates[roomIndex]
|
|
if (!rate) continue
|
|
|
|
const room = roomAvailabilityWithAdjustedRoomCount[roomIndex].find(
|
|
(x) => x?.roomTypeCode === rate.roomInfo.roomTypeCode
|
|
)
|
|
|
|
if (!room || room.status === AvailabilityEnum.NotAvailable) {
|
|
roomIndexesToDeselect.push(roomIndex)
|
|
}
|
|
}
|
|
return roomIndexesToDeselect
|
|
}
|