Merged in fix(SW-2057)-My-stay-crashes-when-at-least-2-children-has-the-same-bed-type (pull request #1649)

feat(SW-2057) Fixed issues with age:bedType for children and that you couldn't check for availability in MyStay

* feat(SW-2057) Fixed issues with age:bedType for children and that you couldn't check for availability in MyStay


Approved-by: Niclas Edenvin
This commit is contained in:
Pontus Dreij
2025-03-27 07:35:02 +00:00
parent 1429f7ec32
commit af2bbcddc3
4 changed files with 55 additions and 12 deletions

View File

@@ -99,7 +99,7 @@ export default function useModifyStay({
bookingCode: bookedRoom.bookingCode ?? undefined,
rateCode: bookedRoom.rateDefinition.rateCode,
roomTypeCode: bookedRoom.roomTypeCode,
lang,
inputLang: lang,
})
if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) {

View File

@@ -1,3 +1,5 @@
import { ChildBedTypeEnum } from "@/constants/booking"
export function formatChildBedPreferences({
childrenAges,
childBedPreferences,
@@ -11,13 +13,51 @@ export function formatChildBedPreferences({
}) {
if (childrenAges.length === 0) return ""
const preferences = childrenAges
.map((age, index) => {
const bed = childBedPreferences[index].bedType
if (!bed) return null
return `${age}:${bed}`
})
.filter(Boolean)
// Find the bed types from preferences
const cribBed = childBedPreferences.find(
(pref) => pref.bedType === ChildBedTypeEnum.Crib
)?.bedType
const parentsBed = childBedPreferences.find(
(pref) => pref.bedType === ChildBedTypeEnum.ParentsBed
)?.bedType
const extraBed = childBedPreferences.find(
(pref) => pref.bedType === ChildBedTypeEnum.ExtraBed
)?.bedType
return `[${preferences.join(", ")}]`
// Step 1: Assign cribs to all children <= 2 years
const preferences = childrenAges.map((age, index) => {
if (age <= 2 && cribBed) return `${age}:${cribBed}`
return { age, index }
})
// Filter out children who still need bed assignment
const remainingChildren = preferences.filter(
(pref): pref is { age: number; index: number } => typeof pref === "object"
)
// Step 2: Assign adults bed to one child <= 5 years if available
const hasParentsBed = childBedPreferences.some(
(pref) => pref.bedType === ChildBedTypeEnum.ParentsBed && pref.quantity > 0
)
if (hasParentsBed && parentsBed) {
const youngChildIndex = remainingChildren.findIndex(
(child) => child.age <= 5
)
if (youngChildIndex >= 0) {
const child = remainingChildren[youngChildIndex]
preferences[child.index] = `${child.age}:${parentsBed}`
remainingChildren.splice(youngChildIndex, 1)
}
}
// Step 3: Assign extra beds to remaining children
if (extraBed) {
remainingChildren.forEach(({ age, index }) => {
preferences[index] = `${age}:${extraBed}`
})
}
// Filter out any null values and join the results
return `[${preferences.filter((pref) => typeof pref === "string").join(", ")}]`
}

View File

@@ -59,7 +59,7 @@ export const selectedRoomAvailabilityInputSchema = z.object({
roomTypeCode: z.string(),
counterRateCode: z.string().optional(),
packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(),
lang: z.nativeEnum(Lang).optional(),
inputLang: z.nativeEnum(Lang).optional(),
redemption: z.boolean().optional(),
})

View File

@@ -593,8 +593,11 @@ export const getRoomAvailability = async (
counterRateCode,
roomTypeCode,
redemption,
inputLang,
} = input
const language = inputLang ?? lang
const params: Record<string, string | number | undefined> = {
roomStayStartDate,
roomStayEndDate,
@@ -602,7 +605,7 @@ export const getRoomAvailability = async (
...(children && { children }),
...(bookingCode && { bookingCode }),
...(redemption && { isRedemption: "true" }),
language: toApiLang(lang),
language: toApiLang(language),
}
metrics.selectedRoomAvailability.counter.add(1, {
@@ -685,7 +688,7 @@ export const getRoomAvailability = async (
{
hotelId,
isCardOnlyPayment: false,
language: lang,
language,
},
serviceToken ?? token
)