fix: change euro price to user's currency + merge state correctly

This commit is contained in:
Christel Westerberg
2024-12-03 13:59:35 +01:00
parent 4dbdf81090
commit 528107e0ef
4 changed files with 58 additions and 46 deletions

View File

@@ -77,9 +77,9 @@ export function subtract(...nums: (number | string | undefined)[]) {
export function getInitialRoomPrice(roomRate: RoomRate, isMember: boolean) {
if (isMember && roomRate.memberRate) {
return {
euro: {
currency: CurrencyEnum.EUR,
price: roomRate.memberRate.requestedPrice?.pricePerStay ?? 0,
requested: roomRate.memberRate.requestedPrice && {
currency: roomRate.memberRate.requestedPrice.currency,
price: roomRate.memberRate.requestedPrice.pricePerStay,
},
local: {
currency: roomRate.memberRate.localPrice.currency,
@@ -89,9 +89,9 @@ export function getInitialRoomPrice(roomRate: RoomRate, isMember: boolean) {
}
return {
euro: {
currency: CurrencyEnum.EUR,
price: roomRate.publicRate.requestedPrice?.pricePerStay ?? 0,
requested: roomRate.publicRate.requestedPrice && {
currency: roomRate.publicRate.requestedPrice.currency,
price: roomRate.publicRate.requestedPrice.pricePerStay,
},
local: {
currency: roomRate.publicRate.localPrice.currency,
@@ -103,9 +103,9 @@ export function getInitialRoomPrice(roomRate: RoomRate, isMember: boolean) {
export function getInitialTotalPrice(roomRate: RoomRate, isMember: boolean) {
if (isMember && roomRate.memberRate) {
return {
euro: {
currency: CurrencyEnum.EUR,
price: roomRate.memberRate.requestedPrice?.pricePerStay ?? 0,
requested: roomRate.memberRate.requestedPrice && {
currency: roomRate.memberRate.requestedPrice.currency,
price: roomRate.memberRate.requestedPrice.pricePerStay,
},
local: {
currency: roomRate.memberRate.localPrice.currency,
@@ -115,9 +115,9 @@ export function getInitialTotalPrice(roomRate: RoomRate, isMember: boolean) {
}
return {
euro: {
currency: CurrencyEnum.EUR,
price: roomRate.publicRate.requestedPrice?.pricePerStay ?? 0,
requested: roomRate.publicRate.requestedPrice && {
currency: roomRate.publicRate.requestedPrice.currency,
price: roomRate.publicRate.requestedPrice.pricePerStay,
},
local: {
currency: roomRate.publicRate.localPrice.currency,
@@ -165,31 +165,31 @@ export function calcTotalPrice(
totalPrice: state.totalPrice,
}
if (state.requestedPrice?.pricePerStay) {
roomAndTotalPrice.roomPrice.euro = {
currency: CurrencyEnum.EUR,
roomAndTotalPrice.roomPrice.requested = {
currency: state.requestedPrice.currency,
price: state.requestedPrice.pricePerStay,
}
let totalPriceEuro = state.requestedPrice.pricePerStay
let totalPriceRequested = state.requestedPrice.pricePerStay
if (state.breakfast) {
totalPriceEuro = add(
totalPriceEuro,
totalPriceRequested = add(
totalPriceRequested,
state.breakfast.requestedPrice.totalPrice
)
}
if (state.packages) {
totalPriceEuro = state.packages.reduce((total, pkg) => {
totalPriceRequested = state.packages.reduce((total, pkg) => {
if (pkg.requestedPrice.totalPrice) {
total = add(total, pkg.requestedPrice.totalPrice)
}
return total
}, totalPriceEuro)
}, totalPriceRequested)
}
roomAndTotalPrice.totalPrice.euro = {
currency: CurrencyEnum.EUR,
price: totalPriceEuro,
roomAndTotalPrice.totalPrice.requested = {
currency: state.requestedPrice.currency,
price: totalPriceRequested,
}
}