64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
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)
|