Files
web/packages/trpc/lib/routers/hotels/schemas/packages.ts
Joakim Jäderberg 7dee6d5083 Merged in chore/move-enter-details (pull request #2778)
Chore/move enter details

Approved-by: Anton Gunnarsson
2025-09-11 07:16:24 +00:00

70 lines
1.9 KiB
TypeScript

import { z } from "zod"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { BreakfastPackageEnum } from "../../../enums/breakfast"
import { PackageTypeEnum } from "../../../enums/packages"
import { RoomPackageCodeEnum } from "../../../enums/roomFilter"
import { imageSchema } from "./image"
// TODO: Remove optional and default when the API change has been deployed
export const packagePriceSchema = z
.object({
currency: z.nativeEnum(CurrencyEnum).default(CurrencyEnum.Unknown),
price: z.number(),
totalPrice: z.number(),
})
.optional()
.default({
currency: CurrencyEnum.Unknown,
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(imageSchema),
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 type BreakfastPackage = z.output<typeof breakfastPackageSchema>
export const breakfastPackageSchema = z.object({
code: z.string(),
description: z.string(),
localPrice: packagePriceSchema,
requestedPrice: packagePriceSchema,
packageType: z.enum([
PackageTypeEnum.BreakfastAdult,
PackageTypeEnum.BreakfastChildren,
]),
})
export const ancillaryPackageSchema = z.object({
categoryName: z.string(),
ancillaryContent: z.array(ancillaryContentSchema),
})