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