Files
web/apps/scandic-web/server/routers/hotels/schemas/packages.ts
Niclas Edenvin fef3a785d0 Merged in feat/sw-1688-list-breakfast (pull request #1615)
Feat/sw-1688 list breakfast

Approved-by: Pontus Dreij
2025-03-25 09:56:05 +00:00

65 lines
1.8 KiB
TypeScript

import { z } from "zod"
import { imageSizesSchema } from "./image"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
import { PackageTypeEnum } from "@/types/enums/packages"
// TODO: Remove optional and default when the API change has been deployed
export const packagePriceSchema = z
.object({
currency: z.string().default("N/A"),
price: z.number(),
totalPrice: z.number(),
})
.optional()
.default({
currency: "N/A",
price: 0,
totalPrice: 0,
})
const inventorySchema = z.object({
date: z.string(),
total: z.number(),
available: z.number(),
})
export const ancillaryContentSchema = z.object({
status: z.string(),
id: z.string(),
variants: z.object({
ancillary: z.object({ id: z.string(), price: packagePriceSchema }),
ancillaryLoyalty: z
.object({ points: z.number(), code: z.string() })
.optional(),
}),
title: z.string(),
descriptions: z.object({ html: z.string() }),
images: z.array(z.object({ imageSizes: imageSizesSchema })),
requiresDeliveryTime: z.boolean(),
})
export const packageSchema = z.object({
code: z.nativeEnum({ ...RoomPackageCodeEnum, ...BreakfastPackageEnum }),
description: z.string(),
inventories: z.array(inventorySchema),
itemCode: z.string().default(""),
localPrice: packagePriceSchema,
requestedPrice: packagePriceSchema,
})
export const breakfastPackageSchema = z.object({
code: z.string(),
description: z.string(),
localPrice: packagePriceSchema,
requestedPrice: packagePriceSchema,
packageType: z.literal(PackageTypeEnum.BreakfastAdult),
})
export const ancillaryPackageSchema = z.object({
categoryName: z.string(),
ancillaryContent: z.array(ancillaryContentSchema),
})