fix: rename children to childrenInRoom
This commit is contained in:
18
utils/url.ts
18
utils/url.ts
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user