Files
web/packages/trpc/lib/routers/hotels/schemas/hotel.ts
Anton Gunnarsson 002d093af4 Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)
feat(SW-2863): Move contentstack router to trpc package

* Add exports to packages and lint rule to prevent relative imports

* Add env to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* WIP first step

* update internal imports in trpc

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package


Approved-by: Linus Flood
2025-06-26 07:53:01 +00:00

85 lines
2.8 KiB
TypeScript

import { z } from "zod"
import {
nullableArrayObjectValidator,
nullableArrayStringValidator,
} from "@scandic-hotels/common/utils/zod/arrayValidator"
import { nullableNumberValidator } from "@scandic-hotels/common/utils/zod/numberValidator"
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
import { addressSchema } from "./hotel/address"
import { contactInformationSchema } from "./hotel/contactInformation"
import { hotelContentSchema } from "./hotel/content"
import { detailedFacilitiesSchema } from "./hotel/detailedFacility"
import { hotelFactsSchema } from "./hotel/facts"
import { healthFacilitiesSchema } from "./hotel/healthFacilities"
import { includeSchema } from "./hotel/include"
import { locationSchema } from "./hotel/location"
import { merchantInformationSchema } from "./hotel/merchantInformation"
import { parkingSchema } from "./hotel/parking"
import { pointOfInterestsSchema } from "./hotel/poi"
import { ratingsSchema } from "./hotel/rating"
import { rewardNightSchema } from "./hotel/rewardNight"
import { socialMediaSchema } from "./hotel/socialMedia"
import { specialAlertsSchema } from "./hotel/specialAlerts"
import { imageSchema } from "./image"
export const attributesSchema = z.object({
address: addressSchema,
cityId: nullableStringValidator,
cityName: nullableStringValidator,
contactInformation: contactInformationSchema,
countryCode: nullableStringValidator,
detailedFacilities: detailedFacilitiesSchema,
galleryImages: z
.array(imageSchema)
.nullish()
.transform((arr) => (arr ? arr.filter(Boolean) : [])),
healthFacilities: healthFacilitiesSchema,
hotelContent: hotelContentSchema,
hotelFacts: hotelFactsSchema,
hotelType: nullableStringValidator,
isActive: z.boolean(),
isPublished: z.boolean(),
keywords: nullableArrayStringValidator,
location: locationSchema,
merchantInformationData: merchantInformationSchema,
name: nullableStringValidator,
operaId: nullableStringValidator,
parking: nullableArrayObjectValidator(parkingSchema),
pointsOfInterest: pointOfInterestsSchema,
ratings: ratingsSchema,
rewardNight: rewardNightSchema,
socialMedia: socialMediaSchema,
specialAlerts: specialAlertsSchema,
vat: nullableNumberValidator,
})
export const includedSchema = z
.array(includeSchema)
.default([])
.transform((data) =>
data.filter((item) => {
if (item) {
if ("isPublished" in item && item.isPublished === false) {
return false
}
return true
}
return false
})
)
const relationshipSchema = z.object({
links: z.object({
related: z.string(),
}),
})
export const relationshipsSchema = z.object({
meetingRooms: relationshipSchema,
nearbyHotels: relationshipSchema,
restaurants: relationshipSchema,
roomCategories: relationshipSchema,
})