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, bookingCode: bookedRoom.bookingCode ?? undefined,
rateCode: bookedRoom.rateDefinition.rateCode, rateCode: bookedRoom.rateDefinition.rateCode,
roomTypeCode: bookedRoom.roomTypeCode, roomTypeCode: bookedRoom.roomTypeCode,
lang, inputLang: lang,
}) })
if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) { if (!data?.selectedRoom || data.selectedRoom.roomsLeft <= 0) {

View File

@@ -1,3 +1,5 @@
import { ChildBedTypeEnum } from "@/constants/booking"
export function formatChildBedPreferences({ export function formatChildBedPreferences({
childrenAges, childrenAges,
childBedPreferences, childBedPreferences,
@@ -11,13 +13,51 @@ export function formatChildBedPreferences({
}) { }) {
if (childrenAges.length === 0) return "" if (childrenAges.length === 0) return ""
const preferences = childrenAges // Find the bed types from preferences
.map((age, index) => { const cribBed = childBedPreferences.find(
const bed = childBedPreferences[index].bedType (pref) => pref.bedType === ChildBedTypeEnum.Crib
if (!bed) return null )?.bedType
return `${age}:${bed}` const parentsBed = childBedPreferences.find(
}) (pref) => pref.bedType === ChildBedTypeEnum.ParentsBed
.filter(Boolean) )?.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(), roomTypeCode: z.string(),
counterRateCode: z.string().optional(), counterRateCode: z.string().optional(),
packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(), packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(),
lang: z.nativeEnum(Lang).optional(), inputLang: z.nativeEnum(Lang).optional(),
redemption: z.boolean().optional(), redemption: z.boolean().optional(),
}) })

View File

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