feat(SW-717) Fixed bug where available rooms didn't show if there where also unavaible dublicates.
This commit is contained in:
@@ -22,83 +22,98 @@ export function filterDuplicateRoomTypesByLowestPrice(
|
|||||||
const roomMap = new Map()
|
const roomMap = new Map()
|
||||||
|
|
||||||
roomConfigurations.forEach((room) => {
|
roomConfigurations.forEach((room) => {
|
||||||
const { roomType, products } = room
|
const { roomType, products, status } = room
|
||||||
|
|
||||||
if (!duplicateRoomTypes.has(roomType)) {
|
if (!duplicateRoomTypes.has(roomType)) {
|
||||||
roomMap.set(roomType, room)
|
roomMap.set(roomType, room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
products.forEach((product) => {
|
const previousRoom = roomMap.get(roomType)
|
||||||
const { productType } = product
|
|
||||||
const publicProduct = productType.public || {
|
|
||||||
requestedPrice: null,
|
|
||||||
localPrice: null,
|
|
||||||
}
|
|
||||||
const memberProduct = productType.member || {
|
|
||||||
requestedPrice: null,
|
|
||||||
localPrice: null,
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
// Prioritize 'Available' status
|
||||||
requestedPrice: publicRequestedPrice,
|
if (status === "Available" && previousRoom?.status === "NotAvailable") {
|
||||||
localPrice: publicLocalPrice,
|
roomMap.set(roomType, room)
|
||||||
} = publicProduct
|
return
|
||||||
const {
|
}
|
||||||
requestedPrice: memberRequestedPrice,
|
|
||||||
localPrice: memberLocalPrice,
|
|
||||||
} = memberProduct
|
|
||||||
|
|
||||||
const previousLowest = roomMap.get(roomType)
|
if (status === "NotAvailable" && previousRoom?.status === "Available") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (previousRoom) {
|
||||||
|
products.forEach((product) => {
|
||||||
|
const { productType } = product
|
||||||
|
const publicProduct = productType.public || {
|
||||||
|
requestedPrice: null,
|
||||||
|
localPrice: null,
|
||||||
|
}
|
||||||
|
const memberProduct = productType.member || {
|
||||||
|
requestedPrice: null,
|
||||||
|
localPrice: null,
|
||||||
|
}
|
||||||
|
|
||||||
const currentRequestedPrice = Math.min(
|
const {
|
||||||
Number(publicRequestedPrice?.pricePerNight) ?? Infinity,
|
requestedPrice: publicRequestedPrice,
|
||||||
Number(memberRequestedPrice?.pricePerNight) ?? Infinity
|
localPrice: publicLocalPrice,
|
||||||
)
|
} = publicProduct
|
||||||
const currentLocalPrice = Math.min(
|
const {
|
||||||
Number(publicLocalPrice?.pricePerNight) ?? Infinity,
|
requestedPrice: memberRequestedPrice,
|
||||||
Number(memberLocalPrice?.pricePerNight) ?? Infinity
|
localPrice: memberLocalPrice,
|
||||||
)
|
} = memberProduct
|
||||||
|
|
||||||
if (
|
const previousLowest = roomMap.get(roomType)
|
||||||
!previousLowest ||
|
|
||||||
currentRequestedPrice <
|
const currentRequestedPrice = Math.min(
|
||||||
Math.min(
|
Number(publicRequestedPrice?.pricePerNight) ?? Infinity,
|
||||||
Number(
|
Number(memberRequestedPrice?.pricePerNight) ?? Infinity
|
||||||
previousLowest.products[0].productType.public.requestedPrice
|
)
|
||||||
?.pricePerNight
|
const currentLocalPrice = Math.min(
|
||||||
) ?? Infinity,
|
Number(publicLocalPrice?.pricePerNight) ?? Infinity,
|
||||||
Number(
|
Number(memberLocalPrice?.pricePerNight) ?? Infinity
|
||||||
previousLowest.products[0].productType.member?.requestedPrice
|
)
|
||||||
?.pricePerNight
|
|
||||||
) ?? Infinity
|
if (
|
||||||
) ||
|
!previousLowest ||
|
||||||
(currentRequestedPrice ===
|
currentRequestedPrice <
|
||||||
Math.min(
|
|
||||||
Number(
|
|
||||||
previousLowest.products[0].productType.public.requestedPrice
|
|
||||||
?.pricePerNight
|
|
||||||
) ?? Infinity,
|
|
||||||
Number(
|
|
||||||
previousLowest.products[0].productType.member?.requestedPrice
|
|
||||||
?.pricePerNight
|
|
||||||
) ?? Infinity
|
|
||||||
) &&
|
|
||||||
currentLocalPrice <
|
|
||||||
Math.min(
|
Math.min(
|
||||||
Number(
|
Number(
|
||||||
previousLowest.products[0].productType.public.localPrice
|
previousLowest.products[0].productType.public.requestedPrice
|
||||||
?.pricePerNight
|
?.pricePerNight
|
||||||
) ?? Infinity,
|
) ?? Infinity,
|
||||||
Number(
|
Number(
|
||||||
previousLowest.products[0].productType.member?.localPrice
|
previousLowest.products[0].productType.member?.requestedPrice
|
||||||
?.pricePerNight
|
?.pricePerNight
|
||||||
) ?? Infinity
|
) ?? Infinity
|
||||||
))
|
) ||
|
||||||
) {
|
(currentRequestedPrice ===
|
||||||
roomMap.set(roomType, room)
|
Math.min(
|
||||||
}
|
Number(
|
||||||
})
|
previousLowest.products[0].productType.public.requestedPrice
|
||||||
|
?.pricePerNight
|
||||||
|
) ?? Infinity,
|
||||||
|
Number(
|
||||||
|
previousLowest.products[0].productType.member?.requestedPrice
|
||||||
|
?.pricePerNight
|
||||||
|
) ?? Infinity
|
||||||
|
) &&
|
||||||
|
currentLocalPrice <
|
||||||
|
Math.min(
|
||||||
|
Number(
|
||||||
|
previousLowest.products[0].productType.public.localPrice
|
||||||
|
?.pricePerNight
|
||||||
|
) ?? Infinity,
|
||||||
|
Number(
|
||||||
|
previousLowest.products[0].productType.member?.localPrice
|
||||||
|
?.pricePerNight
|
||||||
|
) ?? Infinity
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
roomMap.set(roomType, room)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
roomMap.set(roomType, room)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return Array.from(roomMap.values())
|
return Array.from(roomMap.values())
|
||||||
|
|||||||
Reference in New Issue
Block a user