fix: rename children to childrenInRoom

This commit is contained in:
Christel Westerberg
2025-01-14 12:25:17 +01:00
parent b2935114e3
commit bcae63e3fc
26 changed files with 104 additions and 91 deletions

View File

@@ -26,7 +26,7 @@ const keyedSearchParams = new Map([
["fromdate", "fromDate"],
["todate", "toDate"],
["hotel", "hotelId"],
["child", "children"],
["child", "childrenInRoom"],
])
export function getKeyFromSearchParam(key: string): string {
@@ -71,19 +71,19 @@ export function convertSearchParamsToObj<T extends PartialRoom>(
roomObject[index].adults = Number(value)
// Child is an array, so we need to handle it separately
} else if (roomObjectKey === "children") {
} else if (roomObjectKey === "childrenInRoom") {
const childIndex = Number(keys[3])
const childKey = keys[4] as keyof Child
if (
!("children" in roomObject[index]) ||
!Array.isArray(roomObject[index].children)
!("childrenInRoom" in roomObject[index]) ||
!Array.isArray(roomObject[index].childrenInRoom)
) {
roomObject[index].children = []
roomObject[index].childrenInRoom = []
}
roomObject[index].children![childIndex] = {
...roomObject[index].children![childIndex],
roomObject[index].childrenInRoom![childIndex] = {
...roomObject[index].childrenInRoom![childIndex],
[childKey]: Number(value),
}
} else if (roomObjectKey === "packages") {
@@ -115,8 +115,8 @@ export function convertObjToSearchParams<T>(
item.adults.toString()
)
}
if (item?.children) {
item.children.forEach((child, childIndex) => {
if (item?.childrenInRoom) {
item.childrenInRoom.forEach((child, childIndex) => {
bookingSearchParams.set(
`room[${index}].child[${childIndex}].age`,
child.age.toString()