Files
web/server/routers/hotels/schemas/room.ts
Tobias Johansson 1018b3ebcd Merged in feat/SW-1169-map-bedtype-icons (pull request #1113)
Feat/SW-1169 map bedtype icons

* feat(SW-1169): Added bed icons

* fix(SW-1169): update fill rule property

* fix(SW-1169): update clip rule prop

* feat(SW-1169): Added way of rendering bed type icons with extra beds

* feat(SW-1169): update room schema to map mainBed to enum

* feat(SW-1169): update bedtype icon color

* feat(SW-1169): transform unknown bed types to BedTypeEnum.Other

* test: update mock data with new schema


Approved-by: Christel Westerberg
2025-01-08 13:26:56 +00:00

114 lines
2.8 KiB
TypeScript

import { z } from "zod"
import { BedTypeEnum, ExtraBedTypeEnum } from "@/constants/booking"
import { imageSchema } from "./image"
const roomContentSchema = z.object({
images: z.array(imageSchema),
texts: z.object({
descriptions: z.object({
short: z.string().optional(),
medium: z.string().optional(),
}),
}),
})
const roomTypesSchema = z.object({
name: z.string(),
description: z.string(),
code: z.string(),
roomCount: z.number(),
mainBed: z
.object({
type: z.string(),
description: z.string(),
widthRange: z.object({
min: z.number(),
max: z.number(),
}),
})
.transform((data) => ({
type:
data.type in BedTypeEnum
? (data.type as BedTypeEnum)
: BedTypeEnum.Other,
description: data.description,
widthRange: data.widthRange,
})),
fixedExtraBed: z
.object({
type: z.string(),
description: z.string().optional(),
widthRange: z.object({
min: z.number(),
max: z.number(),
}),
})
.transform((data) => {
return data.type in ExtraBedTypeEnum
? {
type: data.type as ExtraBedTypeEnum,
description: data.description,
}
: undefined
}),
roomSize: z.object({
min: z.number(),
max: z.number(),
}),
occupancy: z.object({
total: z.number(),
adults: z.number(),
children: z.number(),
}),
isLackingCribs: z.boolean(),
isLackingExtraBeds: z.boolean(),
})
const roomFacilitiesSchema = z.object({
availableInAllRooms: z.boolean(),
name: z.string(),
isUniqueSellingPoint: z.boolean(),
sortOrder: z.number(),
icon: z.string().optional(),
})
export const roomSchema = z
.object({
attributes: z.object({
name: z.string(),
sortOrder: z.number(),
content: roomContentSchema,
roomTypes: z.array(roomTypesSchema),
roomFacilities: z.array(roomFacilitiesSchema),
occupancy: z.object({
total: z.number().optional(),
adults: z.number().optional(),
children: z.number().optional(),
}),
roomSize: z.object({
min: z.number(),
max: z.number(),
}),
}),
id: z.string(),
type: z.literal("roomcategories"),
})
.transform((data) => {
return {
descriptions: data.attributes.content.texts.descriptions,
id: data.id,
images: data.attributes.content.images,
name: data.attributes.name,
occupancy: data.attributes.occupancy,
roomSize: data.attributes.roomSize,
roomTypes: data.attributes.roomTypes,
sortOrder: data.attributes.sortOrder,
type: data.type,
roomFacilities: data.attributes.roomFacilities,
}
})
export type RoomType = Pick<z.output<typeof roomSchema>, "roomTypes" | "name">