Merged in fix/metadata-schema (pull request #2893)
fix: Updated metadata schema to handle transformed hotel data * fix: Updated metadata schema to handle transformed hotel data Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
57315baf97
commit
4f151b143e
@@ -21,14 +21,14 @@ function getSubpageDescription(
|
||||
}
|
||||
|
||||
switch (subpageUrl) {
|
||||
case additionalHotelData.hotelParking.nameInUrl:
|
||||
return additionalHotelData.hotelParking.elevatorPitch
|
||||
case additionalHotelData.healthAndFitness.nameInUrl:
|
||||
return additionalHotelData.healthAndFitness.elevatorPitch
|
||||
case additionalHotelData.hotelSpecialNeeds.nameInUrl:
|
||||
return additionalHotelData.hotelSpecialNeeds.elevatorPitch
|
||||
case additionalHotelData.meetingRooms.nameInUrl:
|
||||
return additionalHotelData.meetingRooms.elevatorPitch
|
||||
case additionalHotelData.hotelParking?.nameInUrl:
|
||||
return additionalHotelData.hotelParking?.elevatorPitch
|
||||
case additionalHotelData.healthAndFitness?.nameInUrl:
|
||||
return additionalHotelData.healthAndFitness?.elevatorPitch
|
||||
case additionalHotelData.hotelSpecialNeeds?.nameInUrl:
|
||||
return additionalHotelData.hotelSpecialNeeds?.elevatorPitch
|
||||
case additionalHotelData.meetingRooms?.nameInUrl:
|
||||
return additionalHotelData.meetingRooms?.elevatorPitch
|
||||
default:
|
||||
return null
|
||||
}
|
||||
@@ -57,7 +57,7 @@ export async function getHotelPageDescription(data: RawMetadataSchema) {
|
||||
const location = hotelData.translatedCityName
|
||||
const amenities = hotelData.detailedFacilities
|
||||
|
||||
if (amenities.length < 4) {
|
||||
if (!amenities || amenities.length < 4) {
|
||||
return intl.formatMessage(
|
||||
{ defaultMessage: "{hotelName} in {location}. Book your stay now!" },
|
||||
{ hotelName, location }
|
||||
|
||||
@@ -12,27 +12,28 @@ export function getHotelPageImage(data: RawMetadataSchema) {
|
||||
(restaurant) => restaurant.nameInUrl === subpageUrl
|
||||
)
|
||||
const restaurantImage = restaurantSubPage?.content?.images?.[0]
|
||||
if (restaurantImage) {
|
||||
if (restaurantImage?.src) {
|
||||
subpageImage = {
|
||||
url: restaurantImage.src,
|
||||
alt: restaurantImage.altText || restaurantImage.altText_En || undefined,
|
||||
}
|
||||
} else {
|
||||
switch (subpageUrl) {
|
||||
case additionalHotelData?.hotelParking.nameInUrl:
|
||||
const parkingImage = additionalHotelData?.parkingImages?.heroImages[0]
|
||||
if (parkingImage) {
|
||||
case additionalHotelData?.hotelParking?.nameInUrl:
|
||||
const parkingImage =
|
||||
additionalHotelData?.parkingImages?.heroImages?.[0]
|
||||
if (parkingImage?.src) {
|
||||
subpageImage = {
|
||||
url: parkingImage.src,
|
||||
alt: parkingImage.altText || parkingImage.altText_En || undefined,
|
||||
}
|
||||
}
|
||||
break
|
||||
case additionalHotelData?.healthAndFitness.nameInUrl:
|
||||
const wellnessImage = hotelData.healthFacilities.find(
|
||||
(fac) => fac.content.images.length
|
||||
)?.content.images[0]
|
||||
if (wellnessImage) {
|
||||
case additionalHotelData?.healthAndFitness?.nameInUrl:
|
||||
const wellnessImage = hotelData?.healthFacilities?.find(
|
||||
(fac) => fac?.content?.images?.length
|
||||
)?.content?.images[0]
|
||||
if (wellnessImage?.src) {
|
||||
subpageImage = {
|
||||
url: wellnessImage.src,
|
||||
alt:
|
||||
@@ -40,10 +41,10 @@ export function getHotelPageImage(data: RawMetadataSchema) {
|
||||
}
|
||||
}
|
||||
break
|
||||
case additionalHotelData?.hotelSpecialNeeds.nameInUrl:
|
||||
case additionalHotelData?.hotelSpecialNeeds?.nameInUrl:
|
||||
const accessibilityImage =
|
||||
additionalHotelData?.accessibility?.heroImages[0]
|
||||
if (accessibilityImage) {
|
||||
additionalHotelData?.accessibility?.heroImages?.[0]
|
||||
if (accessibilityImage?.src) {
|
||||
subpageImage = {
|
||||
url: accessibilityImage.src,
|
||||
alt:
|
||||
@@ -53,10 +54,10 @@ export function getHotelPageImage(data: RawMetadataSchema) {
|
||||
}
|
||||
}
|
||||
break
|
||||
case additionalHotelData?.meetingRooms.nameInUrl:
|
||||
case additionalHotelData?.meetingRooms?.nameInUrl:
|
||||
const meetingImage =
|
||||
additionalHotelData?.conferencesAndMeetings?.heroImages[0]
|
||||
if (meetingImage) {
|
||||
additionalHotelData?.conferencesAndMeetings?.heroImages?.[0]
|
||||
if (meetingImage?.src) {
|
||||
subpageImage = {
|
||||
url: meetingImage.src,
|
||||
alt: meetingImage.altText || meetingImage.altText_En || undefined,
|
||||
@@ -77,7 +78,7 @@ export function getHotelPageImage(data: RawMetadataSchema) {
|
||||
additionalHotelData?.gallery?.heroImages?.[0] ||
|
||||
additionalHotelData?.gallery?.smallerImages?.[0]
|
||||
|
||||
if (hotelImage) {
|
||||
if (hotelImage?.src) {
|
||||
return {
|
||||
url: hotelImage.src,
|
||||
alt: hotelImage.altText || undefined,
|
||||
|
||||
@@ -46,7 +46,7 @@ async function getSubpageTitle(
|
||||
}
|
||||
|
||||
switch (subpageUrl) {
|
||||
case additionalHotelData.hotelParking.nameInUrl:
|
||||
case additionalHotelData.hotelParking?.nameInUrl:
|
||||
const parkingTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
@@ -63,7 +63,7 @@ async function getSubpageTitle(
|
||||
return parkingTitleShort
|
||||
}
|
||||
return parkingTitleLong
|
||||
case additionalHotelData.healthAndFitness.nameInUrl:
|
||||
case additionalHotelData.healthAndFitness?.nameInUrl:
|
||||
const wellnessTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
@@ -80,7 +80,7 @@ async function getSubpageTitle(
|
||||
return wellnessTitleShort
|
||||
}
|
||||
return wellnessTitleLong
|
||||
case additionalHotelData.hotelSpecialNeeds.nameInUrl:
|
||||
case additionalHotelData.hotelSpecialNeeds?.nameInUrl:
|
||||
const accessibilityTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
@@ -97,7 +97,7 @@ async function getSubpageTitle(
|
||||
return accessibilityTitleShort
|
||||
}
|
||||
return accessibilityTitleLong
|
||||
case additionalHotelData.meetingRooms.nameInUrl:
|
||||
case additionalHotelData.meetingRooms?.nameInUrl:
|
||||
const meetingsTitleLong = intl.formatMessage(
|
||||
{
|
||||
defaultMessage:
|
||||
|
||||
@@ -7,11 +7,8 @@ import {
|
||||
import { myStay } from "@scandic-hotels/common/constants/routes/myStay"
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { attributesSchema as hotelAttributesSchema } from "../../../routers/hotels/schemas/hotel"
|
||||
import { Country } from "../../../types/country"
|
||||
import { RTETypeEnum } from "../../../types/RTEenums"
|
||||
import { additionalDataAttributesSchema } from "../../hotels/schemas/hotel/include/additionalData"
|
||||
import { imageSchema } from "../../hotels/schemas/image"
|
||||
import { destinationFilterSchema } from "../schemas/destinationFilters"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
@@ -42,15 +39,110 @@ const metaDataBlocksSchema = z
|
||||
.object({
|
||||
json: metaDataJsonSchema,
|
||||
})
|
||||
.optional()
|
||||
.nullable(),
|
||||
.nullish(),
|
||||
})
|
||||
.optional()
|
||||
.nullable(),
|
||||
.nullish(),
|
||||
})
|
||||
)
|
||||
.optional()
|
||||
.nullable()
|
||||
.nullish()
|
||||
|
||||
const metaDataImageSchema = z.object({
|
||||
src: z.string().nullish(),
|
||||
altText: z.string().nullish(),
|
||||
altText_En: z.string().nullish(),
|
||||
})
|
||||
|
||||
const metaDataHotelDataSchema = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
detailedFacilities: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
})
|
||||
)
|
||||
.nullish(),
|
||||
healthFacilities: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
content: z
|
||||
.object({
|
||||
images: z.array(metaDataImageSchema),
|
||||
})
|
||||
.nullish(),
|
||||
})
|
||||
.nullish()
|
||||
)
|
||||
.nullish(),
|
||||
translatedCityName: z.string(),
|
||||
})
|
||||
.nullish()
|
||||
|
||||
const metaDataAdditionalHotelDataSchema = z
|
||||
.object({
|
||||
gallery: z
|
||||
.object({
|
||||
heroImages: z.array(metaDataImageSchema).nullish(),
|
||||
smallerImages: z.array(metaDataImageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
hotelParking: z
|
||||
.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
healthAndFitness: z
|
||||
.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
hotelSpecialNeeds: z
|
||||
.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
meetingRooms: z
|
||||
.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
parkingImages: z
|
||||
.object({
|
||||
heroImages: z.array(metaDataImageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
accessibility: z
|
||||
.object({
|
||||
heroImages: z.array(metaDataImageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
conferencesAndMeetings: z
|
||||
.object({
|
||||
heroImages: z.array(metaDataImageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
})
|
||||
.nullish()
|
||||
|
||||
const metaDataHotelRestaurantsSchema = z
|
||||
.array(
|
||||
z.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
name: z.string().nullish(),
|
||||
content: z
|
||||
.object({
|
||||
images: z.array(metaDataImageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
})
|
||||
)
|
||||
.nullish()
|
||||
|
||||
export const seoMetadataSchema = z
|
||||
.object({
|
||||
@@ -120,45 +212,9 @@ export const rawMetadataSchema = z.object({
|
||||
.string()
|
||||
.nullish()
|
||||
.transform((id) => id?.trim() || null),
|
||||
hotelData: hotelAttributesSchema
|
||||
.pick({
|
||||
name: true,
|
||||
detailedFacilities: true,
|
||||
hotelContent: true,
|
||||
healthFacilities: true,
|
||||
})
|
||||
.merge(
|
||||
z.object({
|
||||
translatedCityName: z.string(),
|
||||
})
|
||||
)
|
||||
.nullish(),
|
||||
additionalHotelData: additionalDataAttributesSchema
|
||||
.pick({
|
||||
gallery: true,
|
||||
hotelParking: true,
|
||||
healthAndFitness: true,
|
||||
hotelSpecialNeeds: true,
|
||||
meetingRooms: true,
|
||||
parkingImages: true,
|
||||
accessibility: true,
|
||||
conferencesAndMeetings: true,
|
||||
})
|
||||
.nullish(),
|
||||
hotelRestaurants: z
|
||||
.array(
|
||||
z.object({
|
||||
nameInUrl: z.string().nullish(),
|
||||
elevatorPitch: z.string().nullish(),
|
||||
name: z.string().nullish(),
|
||||
content: z
|
||||
.object({
|
||||
images: z.array(imageSchema).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
})
|
||||
)
|
||||
.nullish(),
|
||||
hotelData: metaDataHotelDataSchema,
|
||||
additionalHotelData: metaDataAdditionalHotelDataSchema,
|
||||
hotelRestaurants: metaDataHotelRestaurantsSchema,
|
||||
subpageUrl: z.string().nullish(),
|
||||
destinationData: z
|
||||
.object({
|
||||
|
||||
Reference in New Issue
Block a user