feat(SW-201): Added hotel metadata
This commit is contained in:
@@ -4,13 +4,15 @@ import { cache } from "react"
|
||||
import { GetAccountPageMetadata } from "@/lib/graphql/Query/AccountPage/Metadata.graphql"
|
||||
import { GetCollectionPageMetadata } from "@/lib/graphql/Query/CollectionPage/Metadata.graphql"
|
||||
import { GetContentPageMetadata } from "@/lib/graphql/Query/ContentPage/Metadata.graphql"
|
||||
import { GetHotelPageMetadata } from "@/lib/graphql/Query/HotelPage/Metadata.graphql"
|
||||
import { GetLoyaltyPageMetadata } from "@/lib/graphql/Query/LoyaltyPage/Metadata.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
import { contentStackUidWithServiceProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
|
||||
import { getHotelData } from "../../hotels/query"
|
||||
import { metadataSchema } from "./output"
|
||||
import { affix } from "./utils"
|
||||
|
||||
@@ -86,10 +88,10 @@ const fetchMetadata = cache(async function fetchMemoizedMetadata<T>(
|
||||
return response.data
|
||||
})
|
||||
|
||||
function getTransformedMetadata(data: unknown) {
|
||||
async function getTransformedMetadata(data: unknown) {
|
||||
transformMetadataCounter.add(1)
|
||||
console.info("contentstack.metadata transform start")
|
||||
const validatedMetadata = metadataSchema.safeParse(data)
|
||||
const validatedMetadata = await metadataSchema.safeParseAsync(data)
|
||||
|
||||
if (!validatedMetadata.success) {
|
||||
transformMetadataFailCounter.add(1, {
|
||||
@@ -112,7 +114,7 @@ function getTransformedMetadata(data: unknown) {
|
||||
}
|
||||
|
||||
export const metadataQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
get: contentStackUidWithServiceProcedure.query(async ({ ctx }) => {
|
||||
const variables = {
|
||||
lang: ctx.lang,
|
||||
uid: ctx.uid,
|
||||
@@ -139,6 +141,38 @@ export const metadataQueryRouter = router({
|
||||
loyalty_page: RawMetadataSchema
|
||||
}>(GetLoyaltyPageMetadata, variables)
|
||||
return getTransformedMetadata(loyaltyPageResponse.loyalty_page)
|
||||
case PageTypeEnum.hotelPage:
|
||||
const hotelPageResponse = await fetchMetadata<{
|
||||
hotel_page: RawMetadataSchema
|
||||
}>(GetHotelPageMetadata, variables)
|
||||
const hotelPageData = hotelPageResponse.hotel_page
|
||||
const hotelData = hotelPageData.hotel_page_id
|
||||
? await getHotelData(
|
||||
{ hotelId: hotelPageData.hotel_page_id, language: ctx.lang },
|
||||
ctx.serviceToken
|
||||
)
|
||||
: null
|
||||
|
||||
const rawHotelData = hotelPageData
|
||||
|
||||
if (hotelData?.data.attributes) {
|
||||
const attributes = hotelData.data.attributes
|
||||
const images = attributes.gallery?.smallerImages
|
||||
|
||||
rawHotelData.hotelData = {
|
||||
name: attributes.name,
|
||||
city: attributes.cityName,
|
||||
description: attributes.hotelContent.texts.descriptions.short,
|
||||
image: images?.length
|
||||
? {
|
||||
url: images[0].imageSizes.small,
|
||||
alt: images[0].metaData.altText,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
return getTransformedMetadata(rawHotelData)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user