fix: move packages schemas
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
getPackages,
|
||||
getProfileSafely,
|
||||
getSelectedRoomAvailability,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
@@ -22,7 +23,13 @@ export default async function SummaryPage({
|
||||
const { hotel, rooms, fromDate, toDate } =
|
||||
getQueryParamsForEnterDetails(selectRoomParams)
|
||||
|
||||
const { adults, children, roomTypeCode, rateCode } = rooms[0] // TODO: Handle multiple rooms
|
||||
const {
|
||||
adults,
|
||||
children,
|
||||
roomTypeCode,
|
||||
rateCode,
|
||||
packages: packageCodes,
|
||||
} = rooms[0] // TODO: Handle multiple rooms
|
||||
|
||||
const availability = await getSelectedRoomAvailability({
|
||||
hotelId: hotel,
|
||||
@@ -34,6 +41,14 @@ export default async function SummaryPage({
|
||||
roomTypeCode,
|
||||
})
|
||||
const user = await getProfileSafely()
|
||||
const packages = await getPackages({
|
||||
hotelId: hotel,
|
||||
startDate: fromDate,
|
||||
endDate: toDate,
|
||||
adults,
|
||||
children: children?.length,
|
||||
packageCodes,
|
||||
})
|
||||
|
||||
if (!availability) {
|
||||
console.error("No hotel or availability data", availability)
|
||||
@@ -64,6 +79,7 @@ export default async function SummaryPage({
|
||||
},
|
||||
}
|
||||
|
||||
console.log({ packages })
|
||||
return (
|
||||
<>
|
||||
<div className={styles.mobileSummary}>
|
||||
|
||||
@@ -8,7 +8,10 @@ import {
|
||||
|
||||
import { serverClient } from "../server"
|
||||
|
||||
import type { BreackfastPackagesInput } from "@/types/requests/packages"
|
||||
import type {
|
||||
BreackfastPackagesInput,
|
||||
PackagesInput,
|
||||
} from "@/types/requests/packages"
|
||||
|
||||
export const getLocations = cache(async function getMemoizedLocations() {
|
||||
return serverClient().hotel.locations.get()
|
||||
@@ -144,6 +147,12 @@ export const getBreakfastPackages = cache(async function getMemoizedPackages(
|
||||
return serverClient().hotel.packages.breakfast(input)
|
||||
})
|
||||
|
||||
export const getPackages = cache(async function getMemoizedPackages(
|
||||
input: PackagesInput
|
||||
) {
|
||||
return serverClient().hotel.packages.get(input)
|
||||
})
|
||||
|
||||
export const getBookingConfirmation = cache(
|
||||
function getMemoizedBookingConfirmation(confirmationNumber: string) {
|
||||
return serverClient().booking.confirmation({ confirmationNumber })
|
||||
|
||||
@@ -68,3 +68,12 @@ export const getBreakfastPackageInputSchema = z.object({
|
||||
.min(1, { message: "toDate is required" })
|
||||
.pipe(z.coerce.date()),
|
||||
})
|
||||
|
||||
export const getRoomPackagesInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
startDate: z.string(),
|
||||
endDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.number().optional().default(0),
|
||||
packageCodes: z.array(z.string()).optional().default([]),
|
||||
})
|
||||
|
||||
@@ -825,7 +825,7 @@ export const apiLocationsSchema = z.object({
|
||||
),
|
||||
})
|
||||
|
||||
const breakfastPackagePriceSchema = z.object({
|
||||
export const packagePriceSchema = z.object({
|
||||
currency: z.nativeEnum(CurrencyEnum),
|
||||
price: z.string(),
|
||||
totalPrice: z.string(),
|
||||
@@ -834,8 +834,8 @@ const breakfastPackagePriceSchema = z.object({
|
||||
export const breakfastPackageSchema = z.object({
|
||||
code: z.string(),
|
||||
description: z.string(),
|
||||
localPrice: breakfastPackagePriceSchema,
|
||||
requestedPrice: breakfastPackagePriceSchema,
|
||||
localPrice: packagePriceSchema,
|
||||
requestedPrice: packagePriceSchema,
|
||||
packageType: z.literal(PackageTypeEnum.BreakfastAdult),
|
||||
})
|
||||
|
||||
@@ -852,3 +852,40 @@ export const breakfastPackagesSchema = z
|
||||
.transform(({ data }) =>
|
||||
data.attributes.packages.filter((pkg) => pkg.code.match(/^(BRF\d+)$/gm))
|
||||
)
|
||||
|
||||
export const packagesSchema = z.object({
|
||||
code: z.nativeEnum(RoomPackageCodeEnum),
|
||||
itemCode: z.string(),
|
||||
description: z.string(),
|
||||
localPrice: packagePriceSchema,
|
||||
requestedPrice: packagePriceSchema,
|
||||
inventories: z.array(
|
||||
z.object({
|
||||
date: z.string(),
|
||||
total: z.number(),
|
||||
available: z.number(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getRoomPackagesSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
hotelId: z.number(),
|
||||
packages: z.array(packagesSchema),
|
||||
}),
|
||||
relationships: z
|
||||
.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
type: z.string(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => data.data.attributes.packages)
|
||||
|
||||
@@ -28,15 +28,12 @@ import {
|
||||
validateHotelPageRefs,
|
||||
} from "../contentstack/hotelPage/utils"
|
||||
import { getVerifiedUser, parsedUser } from "../user/query"
|
||||
import {
|
||||
getRoomPackagesInputSchema,
|
||||
getRoomPackagesSchema,
|
||||
} from "./schemas/packages"
|
||||
import {
|
||||
getBreakfastPackageInputSchema,
|
||||
getHotelDataInputSchema,
|
||||
getHotelsAvailabilityInputSchema,
|
||||
getRatesInputSchema,
|
||||
getRoomPackagesInputSchema,
|
||||
getRoomsAvailabilityInputSchema,
|
||||
getSelectedRoomAvailabilityInputSchema,
|
||||
type HotelDataInput,
|
||||
@@ -46,6 +43,7 @@ import {
|
||||
getHotelDataSchema,
|
||||
getHotelsAvailabilitySchema,
|
||||
getRatesSchema,
|
||||
getRoomPackagesSchema,
|
||||
getRoomsAvailabilitySchema,
|
||||
} from "./output"
|
||||
import tempRatesData from "./tempRatesData.json"
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
|
||||
export const getRoomPackagesInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
startDate: z.string(),
|
||||
endDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.number().optional().default(0),
|
||||
packageCodes: z.array(z.string()).optional().default([]),
|
||||
})
|
||||
|
||||
export const packagePriceSchema = z
|
||||
.object({
|
||||
currency: z.nativeEnum(CurrencyEnum),
|
||||
price: z.string(),
|
||||
totalPrice: z.string(),
|
||||
})
|
||||
.optional()
|
||||
.default({
|
||||
currency: CurrencyEnum.SEK,
|
||||
price: "0",
|
||||
totalPrice: "0",
|
||||
}) // TODO: Remove optional and default when the API change has been deployed
|
||||
|
||||
export const packagesSchema = z.object({
|
||||
code: z.nativeEnum(RoomPackageCodeEnum),
|
||||
itemCode: z.string(),
|
||||
description: z.string(),
|
||||
localPrice: packagePriceSchema,
|
||||
requestedPrice: packagePriceSchema,
|
||||
inventories: z.array(
|
||||
z.object({
|
||||
date: z.string(),
|
||||
total: z.number(),
|
||||
available: z.number(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getRoomPackagesSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
hotelId: z.number(),
|
||||
packages: z.array(packagesSchema),
|
||||
}),
|
||||
relationships: z
|
||||
.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
type: z.string(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => data.data.attributes.packages)
|
||||
@@ -1,10 +1,10 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import {
|
||||
packagePriceSchema,
|
||||
RateDefinition,
|
||||
RoomConfiguration,
|
||||
} from "@/server/routers/hotels/output"
|
||||
import { packagePriceSchema } from "@/server/routers/hotels/schemas/packages"
|
||||
|
||||
import { RoomPriceSchema } from "./flexibilityOption"
|
||||
import { Rate } from "./selectRate"
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from "zod"
|
||||
import {
|
||||
getRoomPackagesSchema,
|
||||
packagesSchema,
|
||||
} from "@/server/routers/hotels/schemas/packages"
|
||||
} from "@/server/routers/hotels/output"
|
||||
|
||||
export enum RoomPackageCodeEnum {
|
||||
PET_ROOM = "PETR",
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { getBreakfastPackageInputSchema } from "@/server/routers/hotels/input"
|
||||
import {
|
||||
getBreakfastPackageInputSchema,
|
||||
getRoomPackagesInputSchema,
|
||||
} from "@/server/routers/hotels/input"
|
||||
|
||||
export interface BreackfastPackagesInput
|
||||
extends z.input<typeof getBreakfastPackageInputSchema> {}
|
||||
|
||||
export interface PackagesInput
|
||||
extends z.input<typeof getRoomPackagesInputSchema> {}
|
||||
|
||||
Reference in New Issue
Block a user