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