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:
Bianca Widstam
2024-10-30 09:34:54 +00:00
parent 5f7dde16c6
commit eff0d122cd
9 changed files with 45 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import { getLocations } from "@/lib/trpc/memoizedRequests"
import {
fetchAvailableHotels,
generateChildrenString,
getFiltersFromHotels,
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
@@ -42,7 +43,9 @@ export default async function SelectHotelPage({
const selectHotelParamsObject =
getHotelReservationQueryParams(selectHotelParams)
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({
cityId: city.id,

View File

@@ -2,9 +2,11 @@ import { serverClient } from "@/lib/trpc/server"
import { getLang } from "@/i18n/serverContext"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums"
import { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
import { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
import { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
import { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
export async function fetchAvailableHotels(
input: AvailabilityInput
@@ -41,3 +43,19 @@ export function getFiltersFromHotels(hotels: HotelData[]) {
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(",")}]`
}

View File

@@ -8,6 +8,8 @@ import Rooms from "@/components/HotelReservation/SelectRate/Rooms"
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { setLang } from "@/i18n/serverContext"
import { generateChildrenString } from "../select-hotel/utils"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
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 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([
serverClient().hotel.hotelData.get({
@@ -46,8 +51,8 @@ export default async function SelectRatePage({
hotelId: searchParams.hotel,
startDate: searchParams.fromDate,
endDate: searchParams.toDate,
adults: adults,
children: children,
adults,
children: childrenCount,
packageCodes: [
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
RoomPackageCodeEnum.PET_ROOM,

View File

@@ -82,12 +82,12 @@ export default function RateSummary({
{ id: "booking.adults" },
{ totalAdults: roomsAvailability.occupancy?.adults }
)}
{roomsAvailability.occupancy?.children && (
{roomsAvailability.occupancy?.children?.length && (
<>
,{" "}
{intl.formatMessage(
{ id: "booking.children" },
{ totalChildren: roomsAvailability.occupancy.children }
{ totalChildren: roomsAvailability.occupancy.children.length }
)}
</>
)}

View File

@@ -11,7 +11,7 @@ export const getHotelsAvailabilityInputSchema = z.object({
roomStayStartDate: z.string(),
roomStayEndDate: z.string(),
adults: z.number(),
children: z.number().optional().default(0),
children: z.string().optional(),
promotionCode: z.string().optional().default(""),
reservationProfileType: z.string().optional().default(""),
attachedProfileId: z.string().optional().default(""),
@@ -22,7 +22,7 @@ export const getRoomsAvailabilityInputSchema = z.object({
roomStayStartDate: z.string(),
roomStayEndDate: z.string(),
adults: z.number(),
children: z.number().optional().default(0),
children: z.string().optional(),
promotionCode: z.string().optional(),
reservationProfileType: z.string().optional().default(""),
attachedProfileId: z.string().optional().default(""),

View File

@@ -1,5 +1,6 @@
import { z } from "zod"
import { BedTypeEnum } from "@/constants/booking"
import { dt } from "@/lib/dt"
import { toLang } from "@/server/utils"
@@ -458,9 +459,14 @@ export const getHotelDataSchema = z.object({
included: z.array(roomSchema).optional(),
})
export const childrenSchema = z.object({
age: z.number(),
bedType: z.nativeEnum(BedTypeEnum),
})
const occupancySchema = z.object({
adults: z.number(),
children: z.number(),
children: z.array(childrenSchema),
})
const bestPricePerStaySchema = z.object({

View File

@@ -312,13 +312,12 @@ export const hotelQueryRouter = router({
roomStayStartDate,
roomStayEndDate,
adults,
children,
...(children && { children }),
promotionCode,
reservationProfileType,
attachedProfileId,
language: apiLang,
}
hotelsAvailabilityCounter.add(1, {
cityId,
roomStayStartDate,
@@ -437,7 +436,7 @@ export const hotelQueryRouter = router({
roomStayStartDate,
roomStayEndDate,
adults,
children,
...(children && { children }),
promotionCode,
reservationProfileType,
attachedProfileId,

View File

@@ -3,7 +3,7 @@ export type AvailabilityInput = {
roomStayStartDate: string
roomStayEndDate: string
adults: number
children?: number
children?: string
promotionCode?: string
reservationProfileType?: string
attachedProfileId?: string

View File

@@ -1,6 +1,6 @@
import { Product, RoomConfiguration } from "@/server/routers/hotels/output"
interface Child {
export interface Child {
bed: string
age: number
}