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