fix: make sure calculations in booking flow are correct
This commit is contained in:
committed by
Michael Zetterberg
parent
3e0f503314
commit
a222ecfc5c
@@ -5,7 +5,11 @@ import type {
|
||||
RoomConfiguration,
|
||||
} from "@/types/trpc/routers/hotel/roomAvailability"
|
||||
|
||||
export function findProduct(rateCode: string, product: Product) {
|
||||
export function findProduct(
|
||||
rateCode: string,
|
||||
product: Product,
|
||||
counterRateCode = ""
|
||||
) {
|
||||
if ("corporateCheque" in product) {
|
||||
return product.corporateCheque.rateCode === rateCode
|
||||
}
|
||||
@@ -18,21 +22,35 @@ export function findProduct(rateCode: string, product: Product) {
|
||||
return product.voucher.rateCode === rateCode
|
||||
}
|
||||
|
||||
if ("public" in product && product.public) {
|
||||
return product.public.rateCode === rateCode
|
||||
}
|
||||
|
||||
if ("member" in product && product.member) {
|
||||
return product.member.rateCode === rateCode
|
||||
const memberExists = "member" in product
|
||||
const publicExists = "public" in product
|
||||
const isRegularRate = memberExists && publicExists
|
||||
if (isRegularRate) {
|
||||
let isProduct = false
|
||||
if (product.member) {
|
||||
isProduct =
|
||||
product.member.rateCode === rateCode ||
|
||||
product.member.rateCode === counterRateCode
|
||||
}
|
||||
if (product.public) {
|
||||
isProduct =
|
||||
product.public.rateCode === rateCode ||
|
||||
product.public.rateCode === counterRateCode
|
||||
}
|
||||
return isProduct
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function findProductInRoom(rateCode: string, room: RoomConfiguration) {
|
||||
export function findProductInRoom(
|
||||
rateCode: string,
|
||||
room: RoomConfiguration,
|
||||
counterRateCode = ""
|
||||
) {
|
||||
if (room.campaign.length) {
|
||||
const campaignProduct = room.campaign.find((product) =>
|
||||
findProduct(rateCode, product)
|
||||
findProduct(rateCode, product, counterRateCode)
|
||||
)
|
||||
if (campaignProduct) {
|
||||
return campaignProduct
|
||||
@@ -40,7 +58,7 @@ export function findProductInRoom(rateCode: string, room: RoomConfiguration) {
|
||||
}
|
||||
if (room.code.length) {
|
||||
const codeProduct = room.code.find((product) =>
|
||||
findProduct(rateCode, product)
|
||||
findProduct(rateCode, product, counterRateCode)
|
||||
)
|
||||
if (codeProduct) {
|
||||
return codeProduct
|
||||
@@ -56,7 +74,7 @@ export function findProductInRoom(rateCode: string, room: RoomConfiguration) {
|
||||
}
|
||||
if (room.regular.length) {
|
||||
const regularProduct = room.regular.find((product) =>
|
||||
findProduct(rateCode, product)
|
||||
findProduct(rateCode, product, counterRateCode)
|
||||
)
|
||||
if (regularProduct) {
|
||||
return regularProduct
|
||||
@@ -66,6 +84,7 @@ export function findProductInRoom(rateCode: string, room: RoomConfiguration) {
|
||||
|
||||
export function findSelectedRate(
|
||||
rateCode: string,
|
||||
counterRateCode: string,
|
||||
roomTypeCode: string,
|
||||
rooms: RoomConfiguration[] | AvailabilityError
|
||||
) {
|
||||
@@ -76,7 +95,7 @@ export function findSelectedRate(
|
||||
if (room.roomTypeCode !== roomTypeCode) {
|
||||
return false
|
||||
}
|
||||
return findProductInRoom(rateCode, room)
|
||||
return findProductInRoom(rateCode, room, counterRateCode)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ export function createRatesStore({
|
||||
const roomConfiguration = roomConfigurations?.[idx]
|
||||
const selectedRoom = findSelectedRate(
|
||||
room.rateCode,
|
||||
room.counterRateCode,
|
||||
room.roomTypeCode,
|
||||
roomConfiguration
|
||||
)
|
||||
@@ -79,7 +80,11 @@ export function createRatesStore({
|
||||
continue
|
||||
}
|
||||
|
||||
const product = findProductInRoom(room.rateCode, selectedRoom)
|
||||
const product = findProductInRoom(
|
||||
room.rateCode,
|
||||
selectedRoom,
|
||||
room.counterRateCode
|
||||
)
|
||||
if (product) {
|
||||
rateSummary[idx] = {
|
||||
features: selectedRoom.features,
|
||||
@@ -121,13 +126,18 @@ export function createRatesStore({
|
||||
const selectedRate =
|
||||
findSelectedRate(
|
||||
room.rateCode,
|
||||
room.counterRateCode,
|
||||
room.roomTypeCode,
|
||||
roomConfiguration
|
||||
) ?? null
|
||||
|
||||
let product = null
|
||||
if (selectedRate) {
|
||||
product = findProductInRoom(room.rateCode, selectedRate)
|
||||
product = findProductInRoom(
|
||||
room.rateCode,
|
||||
selectedRate,
|
||||
room.counterRateCode
|
||||
)
|
||||
}
|
||||
|
||||
// Since features are fetched async based on query string, we need to read from query string to apply correct filtering
|
||||
|
||||
Reference in New Issue
Block a user