feat: SW-633 Validation for URL data
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { notFound } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
import { dt } from "@/lib/dt"
|
||||||
|
import { getLocations, getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
import { HotelIncludeEnum } from "@/server/routers/hotels/input"
|
import { HotelIncludeEnum } from "@/server/routers/hotels/input"
|
||||||
|
|
||||||
@@ -21,6 +22,18 @@ export default async function SelectRatePage({
|
|||||||
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
||||||
setLang(params.lang)
|
setLang(params.lang)
|
||||||
|
|
||||||
|
const locations = await getLocations()
|
||||||
|
if (!locations || "error" in locations) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const hotel = locations.data.find(
|
||||||
|
(location) =>
|
||||||
|
//@ts-ignore
|
||||||
|
location.operaId == searchParams.hotel
|
||||||
|
)
|
||||||
|
if (!hotel) {
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
const selectRoomParams = new URLSearchParams(searchParams)
|
const selectRoomParams = new URLSearchParams(searchParams)
|
||||||
const selectRoomParamsObject =
|
const selectRoomParamsObject =
|
||||||
getHotelReservationQueryParams(selectRoomParams)
|
getHotelReservationQueryParams(selectRoomParams)
|
||||||
@@ -29,7 +42,16 @@ export default async function SelectRatePage({
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const adults = selectRoomParamsObject.room[0].adults // TODO: Handle multiple rooms
|
const validFromDate =
|
||||||
|
searchParams.fromDate &&
|
||||||
|
dt(searchParams.fromDate).isAfter(dt().subtract(1, "day"))
|
||||||
|
? searchParams.fromDate
|
||||||
|
: dt().utc().format("YYYY-MM-DD")
|
||||||
|
const validToDate =
|
||||||
|
searchParams.toDate && dt(searchParams.toDate).isAfter(validFromDate)
|
||||||
|
? searchParams.toDate
|
||||||
|
: dt().utc().add(1, "day").format("YYYY-MM-DD")
|
||||||
|
const adults = selectRoomParamsObject.room[0].adults || 1 // TODO: Handle multiple rooms
|
||||||
const childrenCount = selectRoomParamsObject.room[0].child?.length
|
const childrenCount = selectRoomParamsObject.room[0].child?.length
|
||||||
const children = selectRoomParamsObject.room[0].child
|
const children = selectRoomParamsObject.room[0].child
|
||||||
? generateChildrenString(selectRoomParamsObject.room[0].child)
|
? generateChildrenString(selectRoomParamsObject.room[0].child)
|
||||||
@@ -43,8 +65,8 @@ export default async function SelectRatePage({
|
|||||||
}),
|
}),
|
||||||
serverClient().hotel.availability.rooms({
|
serverClient().hotel.availability.rooms({
|
||||||
hotelId: parseInt(searchParams.hotel, 10),
|
hotelId: parseInt(searchParams.hotel, 10),
|
||||||
roomStayStartDate: searchParams.fromDate,
|
roomStayStartDate: validFromDate,
|
||||||
roomStayEndDate: searchParams.toDate,
|
roomStayEndDate: validToDate,
|
||||||
adults,
|
adults,
|
||||||
children,
|
children,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user