diff --git a/lib/api/endpoints.ts b/lib/api/endpoints.ts index 7fb7e5e9f..03af495fc 100644 --- a/lib/api/endpoints.ts +++ b/lib/api/endpoints.ts @@ -4,6 +4,7 @@ export namespace endpoints { export const enum v0 { profile = "profile/v0/Profile", + availability = "availability/v0/availabilities/city", } export const enum v1 { profile = "profile/v1/Profile", diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index eb31e729d..2e35d0f1d 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -6,6 +6,17 @@ export const getHotelInputSchema = z.object({ .optional(), }) +export const getAvailabilityInputSchema = z.object({ + cityId: z.string(), + roomStayStartDate: z.string(), + roomStayEndDate: z.string(), + adults: z.number(), + children: z.number().optional(), + promotionCode: z.string().optional(), + reservationProfileType: z.string().optional(), + attachedProfileId: z.string().optional(), +}) + export const getRatesInputSchema = z.object({ hotelId: z.string(), }) diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index 9c55c56eb..e0df1167b 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -468,6 +468,64 @@ export const getHotelDataSchema = z.object({ included: z.array(roomSchema).optional(), }) +const occupancySchema = z.object({ + adults: z.number(), + children: z.number(), +}) + +const bestPricePerStaySchema = z.object({ + currency: z.string(), + amount: z.number(), + regularAmount: z.number(), + memberAmount: z.number(), + discountRate: z.number(), + discountAmount: z.number(), + points: z.number(), + numberOfVouchers: z.number(), + numberOfBonusCheques: z.number(), +}) + +const bestPricePerNightSchema = z.object({ + currency: z.string(), + amount: z.number(), + regularAmount: z.number(), + memberAmount: z.number(), + discountRate: z.number(), + discountAmount: z.number(), + points: z.number(), + numberOfVouchers: z.number(), + numberOfBonusCheques: z.number(), +}) + +const linksSchema = z.object({ + links: z.array( + z.object({ + url: z.string(), + type: z.string(), + }) + ), +}) + +const availabilitySchema = z.object({ + data: z.array( + z.object({ + attributes: z.object({ + checkInDate: z.date(), + checkOutDate: z.date(), + occupancy: occupancySchema, + status: z.string(), + hotelId: z.number(), + ratePlanSet: z.string(), + bestPricePerStay: bestPricePerStaySchema, + bestPricePerNight: bestPricePerNightSchema, + }), + relationships: linksSchema, + }) + ), +}) + +export const getAvailabilitySchema = availabilitySchema + const flexibilityPrice = z.object({ standard: z.number(), member: z.number(), diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index bd8d8f14a..5c0d70054 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -21,11 +21,13 @@ import { validateHotelPageSchema, } from "../contentstack/hotelPage/output" import { + getAvailabilityInputSchema, getFiltersInputSchema, getHotelInputSchema, getRatesInputSchema, } from "./input" import { + getAvailabilitySchema, getFiltersSchema, getHotelDataSchema, getRatesSchema, diff --git a/types/hotel.ts b/types/hotel.ts index ed3b44ed9..0c5938318 100644 --- a/types/hotel.ts +++ b/types/hotel.ts @@ -1,6 +1,10 @@ import { z } from "zod" -import { getHotelDataSchema, roomSchema } from "@/server/routers/hotels/output" +import { + getAvailabilitySchema, + getHotelDataSchema, + roomSchema, +} from "@/server/routers/hotels/output" export type HotelData = z.infer @@ -14,3 +18,5 @@ export type HotelTripAdvisor = | undefined export type RoomData = z.infer + +export type Availability = z.infer