feat/SW-711-update-children-params (pull request #791)
Feat/SW-711 update children params * feat(SW-711): add new child params for availability * feat(SW-711): fix children schema * feat(SW-711): fix optional values * feat(SW-711): add children as parameter iff not undefined * feat(SW-711): add bedType enum * feat(SW-711): remove optional number type * feat(SW-711): fix wrong slash * feat(SW-711): remove optional Approved-by: Hrishikesh Vaipurkar
This commit is contained in:
@@ -5,6 +5,7 @@ import { getLocations } from "@/lib/trpc/memoizedRequests"
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
fetchAvailableHotels,
|
fetchAvailableHotels,
|
||||||
|
generateChildrenString,
|
||||||
getFiltersFromHotels,
|
getFiltersFromHotels,
|
||||||
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
||||||
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
|
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
|
||||||
@@ -42,7 +43,9 @@ export default async function SelectHotelPage({
|
|||||||
const selectHotelParamsObject =
|
const selectHotelParamsObject =
|
||||||
getHotelReservationQueryParams(selectHotelParams)
|
getHotelReservationQueryParams(selectHotelParams)
|
||||||
const adults = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
|
const adults = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
|
||||||
const children = selectHotelParamsObject.room[0].child?.length // TODO: Handle multiple rooms
|
const children = selectHotelParamsObject.room[0].child
|
||||||
|
? generateChildrenString(selectHotelParamsObject.room[0].child)
|
||||||
|
: undefined // TODO: Handle multiple rooms
|
||||||
|
|
||||||
const hotels = await fetchAvailableHotels({
|
const hotels = await fetchAvailableHotels({
|
||||||
cityId: city.id,
|
cityId: city.id,
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import { serverClient } from "@/lib/trpc/server"
|
|||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
|
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
|
||||||
import { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
import { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
||||||
import { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
import { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
||||||
import { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
import { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||||
|
import { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
|
|
||||||
export async function fetchAvailableHotels(
|
export async function fetchAvailableHotels(
|
||||||
input: AvailabilityInput
|
input: AvailabilityInput
|
||||||
@@ -41,3 +43,19 @@ export function getFiltersFromHotels(hotels: HotelData[]) {
|
|||||||
|
|
||||||
return filterList
|
return filterList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bedTypeMap: Record<number, string> = {
|
||||||
|
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
|
||||||
|
[BedTypeEnum.IN_CRIB]: "Crib",
|
||||||
|
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateChildrenString(children: Child[]): string {
|
||||||
|
return `[${children
|
||||||
|
?.map((child) => {
|
||||||
|
const age = child.age
|
||||||
|
const bedType = bedTypeMap[+child.bed]
|
||||||
|
return `${age}:${bedType}`
|
||||||
|
})
|
||||||
|
.join(",")}]`
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import Rooms from "@/components/HotelReservation/SelectRate/Rooms"
|
|||||||
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
|
import { generateChildrenString } from "../select-hotel/utils"
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
import { LangParams, PageArgs } from "@/types/params"
|
import { LangParams, PageArgs } from "@/types/params"
|
||||||
@@ -27,7 +29,10 @@ export default async function SelectRatePage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const adults = selectRoomParamsObject.room[0].adults // TODO: Handle multiple rooms
|
const adults = selectRoomParamsObject.room[0].adults // TODO: Handle multiple rooms
|
||||||
const children = selectRoomParamsObject.room[0].child?.length // TODO: Handle multiple rooms
|
const childrenCount = selectRoomParamsObject.room[0].child?.length
|
||||||
|
const children = selectRoomParamsObject.room[0].child
|
||||||
|
? generateChildrenString(selectRoomParamsObject.room[0].child)
|
||||||
|
: undefined // TODO: Handle multiple rooms
|
||||||
|
|
||||||
const [hotelData, roomsAvailability, packages, user] = await Promise.all([
|
const [hotelData, roomsAvailability, packages, user] = await Promise.all([
|
||||||
serverClient().hotel.hotelData.get({
|
serverClient().hotel.hotelData.get({
|
||||||
@@ -46,8 +51,8 @@ export default async function SelectRatePage({
|
|||||||
hotelId: searchParams.hotel,
|
hotelId: searchParams.hotel,
|
||||||
startDate: searchParams.fromDate,
|
startDate: searchParams.fromDate,
|
||||||
endDate: searchParams.toDate,
|
endDate: searchParams.toDate,
|
||||||
adults: adults,
|
adults,
|
||||||
children: children,
|
children: childrenCount,
|
||||||
packageCodes: [
|
packageCodes: [
|
||||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||||
RoomPackageCodeEnum.PET_ROOM,
|
RoomPackageCodeEnum.PET_ROOM,
|
||||||
|
|||||||
@@ -82,12 +82,12 @@ export default function RateSummary({
|
|||||||
{ id: "booking.adults" },
|
{ id: "booking.adults" },
|
||||||
{ totalAdults: roomsAvailability.occupancy?.adults }
|
{ totalAdults: roomsAvailability.occupancy?.adults }
|
||||||
)}
|
)}
|
||||||
{roomsAvailability.occupancy?.children && (
|
{roomsAvailability.occupancy?.children?.length && (
|
||||||
<>
|
<>
|
||||||
,{" "}
|
,{" "}
|
||||||
{intl.formatMessage(
|
{intl.formatMessage(
|
||||||
{ id: "booking.children" },
|
{ id: "booking.children" },
|
||||||
{ totalChildren: roomsAvailability.occupancy.children }
|
{ totalChildren: roomsAvailability.occupancy.children.length }
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const getHotelsAvailabilityInputSchema = z.object({
|
|||||||
roomStayStartDate: z.string(),
|
roomStayStartDate: z.string(),
|
||||||
roomStayEndDate: z.string(),
|
roomStayEndDate: z.string(),
|
||||||
adults: z.number(),
|
adults: z.number(),
|
||||||
children: z.number().optional().default(0),
|
children: z.string().optional(),
|
||||||
promotionCode: z.string().optional().default(""),
|
promotionCode: z.string().optional().default(""),
|
||||||
reservationProfileType: z.string().optional().default(""),
|
reservationProfileType: z.string().optional().default(""),
|
||||||
attachedProfileId: z.string().optional().default(""),
|
attachedProfileId: z.string().optional().default(""),
|
||||||
@@ -22,7 +22,7 @@ export const getRoomsAvailabilityInputSchema = z.object({
|
|||||||
roomStayStartDate: z.string(),
|
roomStayStartDate: z.string(),
|
||||||
roomStayEndDate: z.string(),
|
roomStayEndDate: z.string(),
|
||||||
adults: z.number(),
|
adults: z.number(),
|
||||||
children: z.number().optional().default(0),
|
children: z.string().optional(),
|
||||||
promotionCode: z.string().optional(),
|
promotionCode: z.string().optional(),
|
||||||
reservationProfileType: z.string().optional().default(""),
|
reservationProfileType: z.string().optional().default(""),
|
||||||
attachedProfileId: z.string().optional().default(""),
|
attachedProfileId: z.string().optional().default(""),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { BedTypeEnum } from "@/constants/booking"
|
||||||
import { dt } from "@/lib/dt"
|
import { dt } from "@/lib/dt"
|
||||||
import { toLang } from "@/server/utils"
|
import { toLang } from "@/server/utils"
|
||||||
|
|
||||||
@@ -458,9 +459,14 @@ export const getHotelDataSchema = z.object({
|
|||||||
included: z.array(roomSchema).optional(),
|
included: z.array(roomSchema).optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const childrenSchema = z.object({
|
||||||
|
age: z.number(),
|
||||||
|
bedType: z.nativeEnum(BedTypeEnum),
|
||||||
|
})
|
||||||
|
|
||||||
const occupancySchema = z.object({
|
const occupancySchema = z.object({
|
||||||
adults: z.number(),
|
adults: z.number(),
|
||||||
children: z.number(),
|
children: z.array(childrenSchema),
|
||||||
})
|
})
|
||||||
|
|
||||||
const bestPricePerStaySchema = z.object({
|
const bestPricePerStaySchema = z.object({
|
||||||
|
|||||||
@@ -312,13 +312,12 @@ export const hotelQueryRouter = router({
|
|||||||
roomStayStartDate,
|
roomStayStartDate,
|
||||||
roomStayEndDate,
|
roomStayEndDate,
|
||||||
adults,
|
adults,
|
||||||
children,
|
...(children && { children }),
|
||||||
promotionCode,
|
promotionCode,
|
||||||
reservationProfileType,
|
reservationProfileType,
|
||||||
attachedProfileId,
|
attachedProfileId,
|
||||||
language: apiLang,
|
language: apiLang,
|
||||||
}
|
}
|
||||||
|
|
||||||
hotelsAvailabilityCounter.add(1, {
|
hotelsAvailabilityCounter.add(1, {
|
||||||
cityId,
|
cityId,
|
||||||
roomStayStartDate,
|
roomStayStartDate,
|
||||||
@@ -437,7 +436,7 @@ export const hotelQueryRouter = router({
|
|||||||
roomStayStartDate,
|
roomStayStartDate,
|
||||||
roomStayEndDate,
|
roomStayEndDate,
|
||||||
adults,
|
adults,
|
||||||
children,
|
...(children && { children }),
|
||||||
promotionCode,
|
promotionCode,
|
||||||
reservationProfileType,
|
reservationProfileType,
|
||||||
attachedProfileId,
|
attachedProfileId,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ export type AvailabilityInput = {
|
|||||||
roomStayStartDate: string
|
roomStayStartDate: string
|
||||||
roomStayEndDate: string
|
roomStayEndDate: string
|
||||||
adults: number
|
adults: number
|
||||||
children?: number
|
children?: string
|
||||||
promotionCode?: string
|
promotionCode?: string
|
||||||
reservationProfileType?: string
|
reservationProfileType?: string
|
||||||
attachedProfileId?: string
|
attachedProfileId?: string
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
|
||||||
|
|
||||||
interface Child {
|
export interface Child {
|
||||||
bed: string
|
bed: string
|
||||||
age: number
|
age: number
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user