fix: align placeholder handling for all hotel images in zod
This commit is contained in:
@@ -3,11 +3,7 @@ import { z } from "zod"
|
||||
import { ChildBedTypeEnum, type PaymentMethodEnum } from "@/constants/booking"
|
||||
import { toLang } from "@/server/utils"
|
||||
|
||||
import {
|
||||
imageMetaDataSchema,
|
||||
imageSchema,
|
||||
imageSizesSchema,
|
||||
} from "./schemas/image"
|
||||
import { imageSchema } from "./schemas/image"
|
||||
import { restaurantSchema } from "./schemas/restaurants"
|
||||
import { roomSchema } from "./schemas/room"
|
||||
import { specialAlertsSchema } from "./schemas/specialAlerts"
|
||||
@@ -104,25 +100,7 @@ const locationSchema = z.object({
|
||||
})
|
||||
|
||||
const hotelContentSchema = z.object({
|
||||
images: z
|
||||
.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
.default({
|
||||
metaData: {
|
||||
title: "default image",
|
||||
altText: "default image",
|
||||
altText_En: "default image",
|
||||
copyRight: "default image",
|
||||
},
|
||||
imageSizes: {
|
||||
tiny: "https://placehold.co/1280x720",
|
||||
small: "https://placehold.co/1280x720",
|
||||
medium: "https://placehold.co/1280x720",
|
||||
large: "https://placehold.co/1280x720",
|
||||
},
|
||||
}),
|
||||
images: imageSchema,
|
||||
texts: z.object({
|
||||
facilityInformation: z.string().optional(),
|
||||
surroundingInformation: z.string(),
|
||||
@@ -156,12 +134,7 @@ const detailedFacilitySchema = z.object({
|
||||
|
||||
export const facilitySchema = z.object({
|
||||
headingText: z.string().default(""),
|
||||
heroImages: z.array(
|
||||
z.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
),
|
||||
heroImages: z.array(imageSchema),
|
||||
})
|
||||
|
||||
export const gallerySchema = z.object({
|
||||
|
||||
@@ -1,20 +1,44 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const imageSizesSchema = z.object({
|
||||
const imageSizesSchema = z.object({
|
||||
tiny: z.string(),
|
||||
small: z.string(),
|
||||
medium: z.string(),
|
||||
large: z.string(),
|
||||
})
|
||||
|
||||
export const imageMetaDataSchema = z.object({
|
||||
const imageMetaDataSchema = z.object({
|
||||
title: z.string(),
|
||||
altText: z.string(),
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
})
|
||||
|
||||
export const imageSchema = z.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
const DEFAULT_IMAGE_OBJ = {
|
||||
metaData: {
|
||||
title: "Default image",
|
||||
altText: "Default image",
|
||||
altText_En: "Default image",
|
||||
copyRight: "Default image",
|
||||
},
|
||||
imageSizes: {
|
||||
tiny: "https://placehold.co/1280x720",
|
||||
small: "https://placehold.co/1280x720",
|
||||
medium: "https://placehold.co/1280x720",
|
||||
large: "https://placehold.co/1280x720",
|
||||
},
|
||||
}
|
||||
|
||||
export const imageSchema = z
|
||||
.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
.default(DEFAULT_IMAGE_OBJ)
|
||||
.nullable()
|
||||
.transform((val) => {
|
||||
if (!val) {
|
||||
return DEFAULT_IMAGE_OBJ
|
||||
}
|
||||
return val
|
||||
})
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { imageMetaDataSchema, imageSizesSchema } from "./image"
|
||||
import { imageSchema } from "./image"
|
||||
|
||||
const roomContentSchema = z.object({
|
||||
images: z.array(
|
||||
z.object({
|
||||
metaData: imageMetaDataSchema,
|
||||
imageSizes: imageSizesSchema,
|
||||
})
|
||||
),
|
||||
images: z.array(imageSchema),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
short: z.string().optional(),
|
||||
|
||||
@@ -3,6 +3,8 @@ import { z } from "zod"
|
||||
import { countriesMap } from "@/components/TempDesignSystem/Form/Country/countries"
|
||||
import { getMembership } from "@/utils/user"
|
||||
|
||||
import { imageSchema } from "../hotels/schemas/image"
|
||||
|
||||
export const membershipSchema = z.object({
|
||||
currentPoints: z.number(),
|
||||
expirationDate: z.string(),
|
||||
@@ -60,20 +62,7 @@ export const getStaysSchema = z.object({
|
||||
hotelOperaId: z.string(),
|
||||
hotelInformation: z.object({
|
||||
hotelContent: z.object({
|
||||
images: z.object({
|
||||
metaData: z.object({
|
||||
title: z.string(),
|
||||
altText: z.string(),
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
}),
|
||||
imageSizes: z.object({
|
||||
tiny: z.string(),
|
||||
small: z.string(),
|
||||
medium: z.string(),
|
||||
large: z.string(),
|
||||
}),
|
||||
}),
|
||||
images: imageSchema,
|
||||
}),
|
||||
hotelName: z.string(),
|
||||
cityName: z.string().nullable(),
|
||||
@@ -140,20 +129,7 @@ export const getFriendTransactionsSchema = z.object({
|
||||
city: z.string().default(""),
|
||||
name: z.string().default(""),
|
||||
hotelContent: z.object({
|
||||
images: z.object({
|
||||
metaData: z.object({
|
||||
title: z.string(),
|
||||
altText: z.string(),
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
}),
|
||||
imageSizes: z.object({
|
||||
tiny: z.string(),
|
||||
small: z.string(),
|
||||
medium: z.string(),
|
||||
large: z.string(),
|
||||
}),
|
||||
}),
|
||||
images: imageSchema,
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
|
||||
@@ -2,10 +2,7 @@ import type { z } from "zod"
|
||||
|
||||
import type { Coordinates } from "@/types/components/maps/coordinates"
|
||||
import type { Location } from "@/types/trpc/routers/hotel/locations"
|
||||
import type {
|
||||
imageMetaDataSchema,
|
||||
imageSizesSchema,
|
||||
} from "@/server/routers/hotels/schemas/image"
|
||||
import type { imageSchema } from "@/server/routers/hotels/schemas/image"
|
||||
import type { Child } from "../../bookingWidget/guestsRoomsPicker"
|
||||
import type { HotelData } from "./hotelCardListingProps"
|
||||
import type { CategorizedFilters, Filter } from "./hotelFilters"
|
||||
@@ -24,8 +21,8 @@ export interface SelectHotelMapProps {
|
||||
cityCoordinates: Coordinates
|
||||
}
|
||||
|
||||
type ImageSizes = z.infer<typeof imageSizesSchema>
|
||||
type ImageMetaData = z.infer<typeof imageMetaDataSchema>
|
||||
type ImageSizes = z.infer<typeof imageSchema>["imageSizes"]
|
||||
type ImageMetaData = z.infer<typeof imageSchema>["metaData"]
|
||||
|
||||
export type HotelPin = {
|
||||
name: string
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { z } from "zod"
|
||||
import type { z } from "zod"
|
||||
|
||||
import {
|
||||
import type {
|
||||
checkinSchema,
|
||||
facilitySchema,
|
||||
getHotelDataSchema,
|
||||
parkingSchema,
|
||||
pointOfInterestSchema,
|
||||
} from "@/server/routers/hotels/output"
|
||||
import { imageSchema } from "@/server/routers/hotels/schemas/image"
|
||||
import {
|
||||
import type { imageSchema } from "@/server/routers/hotels/schemas/image"
|
||||
import type {
|
||||
restaurantDaySchema,
|
||||
restaurantOpeningHoursSchema,
|
||||
restaurantSchema,
|
||||
} from "@/server/routers/hotels/schemas/restaurants"
|
||||
import { roomSchema } from "@/server/routers/hotels/schemas/room"
|
||||
import type { roomSchema } from "@/server/routers/hotels/schemas/room"
|
||||
|
||||
export type HotelData = z.output<typeof getHotelDataSchema>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user