feat(SW-874): Updated logic for getLowestPricedDuplicateRooms

This commit is contained in:
Pontus Dreij
2024-11-13 20:27:53 +01:00
parent 7ee7d60307
commit 2beba21323

View File

@@ -46,7 +46,7 @@ export function getLowestPricedDuplicateRooms(
localPrice: memberLocalPrice,
} = memberProduct
const currentLowest = roomMap.get(roomType)
const previousLowest = roomMap.get(roomType)
const currentRequestedPrice = Math.min(
Number(publicRequestedPrice.pricePerNight) ?? Infinity,
@@ -58,17 +58,42 @@ export function getLowestPricedDuplicateRooms(
)
if (
!currentLowest ||
currentRequestedPrice < currentLowest.requestedPrice ||
(currentRequestedPrice === currentLowest.requestedPrice &&
currentLocalPrice < currentLowest.localPrice)
!previousLowest ||
currentRequestedPrice <
Math.min(
Number(
previousLowest.products[0].productType.public.requestedPrice
.pricePerNight
) ?? Infinity,
Number(
previousLowest.products[0].productType.member?.requestedPrice
?.pricePerNight
) ?? Infinity
) ||
(currentRequestedPrice ===
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,
product,
requestedPrice: currentRequestedPrice,
localPrice: currentLocalPrice,
})
roomMap.set(roomType, room)
}
})
})