Merged in chore/move-enter-details (pull request #2778)
Chore/move enter details Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { sumPackages } from "../../../../utils/SelectRate"
|
||||
|
||||
import type { RoomState } from "../../../../stores/enter-details/types"
|
||||
|
||||
export function mapToPrice(rooms: RoomState[], isMember: boolean) {
|
||||
return rooms
|
||||
.filter((room) => room && room.room.roomRate)
|
||||
.map(({ room }, idx) => {
|
||||
const isMainRoom = idx === 0
|
||||
|
||||
const pkgsSum = sumPackages(room.roomFeatures)
|
||||
|
||||
const roomWithoutPrice = {
|
||||
...room,
|
||||
packages: room.roomFeatures,
|
||||
rateDefinition: {
|
||||
isMemberRate: false,
|
||||
},
|
||||
}
|
||||
|
||||
if ("corporateCheque" in room.roomRate) {
|
||||
if (
|
||||
room.roomRate.corporateCheque.localPrice.additionalPricePerStay ||
|
||||
pkgsSum.price
|
||||
) {
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
corporateCheque: {
|
||||
...room.roomRate.corporateCheque.localPrice,
|
||||
additionalPricePerStay:
|
||||
room.roomRate.corporateCheque.localPrice
|
||||
.additionalPricePerStay || 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
corporateCheque: room.roomRate.corporateCheque.localPrice,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if ("redemption" in room.roomRate) {
|
||||
if (
|
||||
room.roomRate.redemption.localPrice.additionalPricePerStay ||
|
||||
pkgsSum.price
|
||||
) {
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
redemption: {
|
||||
...room.roomRate.redemption.localPrice,
|
||||
additionalPricePerStay:
|
||||
room.roomRate.redemption.localPrice.additionalPricePerStay ||
|
||||
0,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
redemption: room.roomRate.redemption.localPrice,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if ("voucher" in room.roomRate) {
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
voucher: room.roomRate.voucher,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const isMemberRate = !!(room.guest.join || room.guest.membershipNo)
|
||||
if ((isMember && isMainRoom) || isMemberRate) {
|
||||
if ("member" in room.roomRate && room.roomRate.member) {
|
||||
if (pkgsSum.price) {
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
rateDefinition: {
|
||||
isMemberRate: true,
|
||||
},
|
||||
price: {
|
||||
regular: {
|
||||
...room.roomRate.member.localPrice,
|
||||
pricePerNight: room.roomRate.member.localPrice.pricePerNight,
|
||||
pricePerStay: room.roomRate.member.localPrice.pricePerStay,
|
||||
regularPricePerStay:
|
||||
(room.roomRate.public?.localPrice.pricePerStay ||
|
||||
room.roomRate.member.localPrice.pricePerStay) +
|
||||
pkgsSum.price,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
rateDefinition: {
|
||||
isMemberRate: true,
|
||||
},
|
||||
price: {
|
||||
regular: {
|
||||
...room.roomRate.member.localPrice,
|
||||
regularPricePerStay:
|
||||
room.roomRate.public?.localPrice.pricePerStay ||
|
||||
room.roomRate.member.localPrice.pricePerStay,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("public" in room.roomRate && room.roomRate.public) {
|
||||
if (pkgsSum.price) {
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
regular: room.roomRate.public.localPrice,
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
...roomWithoutPrice,
|
||||
price: {
|
||||
regular: room.roomRate.public.localPrice,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
logger.error("Unknown roomRate", room.roomRate)
|
||||
throw new Error(`Unknown roomRate`)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user