chore(SW-303): fetch activity card from CS
This commit is contained in:
@@ -1,6 +1,50 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { HotelBlocksTypenameEnum } from "@/types/components/hotelPage/enums"
|
||||
|
||||
export const activityCardSchema = z.object({
|
||||
background_image: z.any(),
|
||||
cta_text: z.string(),
|
||||
heading: z.string(),
|
||||
open_in_new_tab: z.boolean(),
|
||||
scripted_title: z.string().optional(),
|
||||
body_text: z.string(),
|
||||
hotel_page_activities_content_pageConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
url: z.string(),
|
||||
web: z.object({
|
||||
original_url: z.string().optional(),
|
||||
}),
|
||||
system: z.object({
|
||||
locale: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
export const validateHotelPageSchema = z.object({
|
||||
hotel_page: z.object({
|
||||
hotel_page_id: z.string(),
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
content: z
|
||||
.array(
|
||||
z.object({
|
||||
__typename: z.literal(
|
||||
HotelBlocksTypenameEnum.HotelPageContentUpcomingActivitiesCard
|
||||
),
|
||||
upcoming_activities_card: activityCardSchema.optional(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const hotelPageSchema = z.object({
|
||||
hotel_page: z.object({
|
||||
hotel_page_id: z.string(),
|
||||
title: z.string(),
|
||||
@@ -12,5 +56,6 @@ export const validateHotelPageSchema = z.object({
|
||||
export type HotelPageDataRaw = z.infer<typeof validateHotelPageSchema>
|
||||
|
||||
type HotelPageRaw = HotelPageDataRaw["hotel_page"]
|
||||
|
||||
export type HotelPage = HotelPageRaw
|
||||
|
||||
export type ActivityCard = z.infer<typeof activityCardSchema>
|
||||
|
||||
@@ -17,6 +17,9 @@ import {
|
||||
} from "@/server/trpc"
|
||||
import { toApiLang } from "@/server/utils"
|
||||
|
||||
import { makeImageVaultImage } from "@/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
import {
|
||||
HotelPageDataRaw,
|
||||
validateHotelPageSchema,
|
||||
@@ -37,6 +40,7 @@ import {
|
||||
import tempFilterData from "./tempFilterData.json"
|
||||
import tempRatesData from "./tempRatesData.json"
|
||||
|
||||
import { HotelBlocksTypenameEnum } from "@/types/components/hotelPage/enums"
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
|
||||
const meter = metrics.getMeter("trpc.hotels")
|
||||
@@ -52,7 +56,10 @@ const availabilityFailCounter = meter.createCounter(
|
||||
"trpc.hotel.availability-fail"
|
||||
)
|
||||
|
||||
async function getHotelId(locale: string, uid: string | null | undefined) {
|
||||
async function getContenstackData(
|
||||
locale: string,
|
||||
uid: string | null | undefined
|
||||
) {
|
||||
const rawContentStackData = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||
locale,
|
||||
uid,
|
||||
@@ -74,7 +81,7 @@ async function getHotelId(locale: string, uid: string | null | undefined) {
|
||||
return null
|
||||
}
|
||||
|
||||
return hotelPageData.data.hotel_page.hotel_page_id
|
||||
return hotelPageData.data.hotel_page
|
||||
}
|
||||
|
||||
export const hotelQueryRouter = router({
|
||||
@@ -83,7 +90,8 @@ export const hotelQueryRouter = router({
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { lang, uid } = ctx
|
||||
const { include } = input
|
||||
const hotelId = await getHotelId(lang, uid)
|
||||
const contentstackData = await getContenstackData(lang, uid)
|
||||
const hotelId = contentstackData?.hotel_page_id
|
||||
|
||||
if (!hotelId) {
|
||||
throw notFound(`Hotel not found for uid: ${uid}`)
|
||||
@@ -203,6 +211,32 @@ export const hotelQueryRouter = router({
|
||||
})
|
||||
: []
|
||||
|
||||
const activities = contentstackData?.content
|
||||
? contentstackData.content.map((block: any) => {
|
||||
switch (block.__typename) {
|
||||
case HotelBlocksTypenameEnum.HotelPageContentUpcomingActivitiesCard:
|
||||
return {
|
||||
...block.upcoming_activities_card,
|
||||
background_image: makeImageVaultImage(
|
||||
block.upcoming_activities_card.background_image
|
||||
),
|
||||
contentPage:
|
||||
block.upcoming_activities_card?.hotel_page_activities_content_pageConnection?.edges.map(
|
||||
({ node: contentPage }: { node: any }) => {
|
||||
return {
|
||||
href:
|
||||
contentPage.web?.original_url ||
|
||||
removeMultipleSlashes(
|
||||
`/${contentPage.system.locale}/${contentPage.url}`
|
||||
),
|
||||
}
|
||||
}
|
||||
),
|
||||
}
|
||||
}
|
||||
})[0]
|
||||
: null
|
||||
|
||||
getHotelSuccessCounter.add(1, { hotelId, lang, include })
|
||||
console.info(
|
||||
"api.hotels.hotel success",
|
||||
@@ -219,6 +253,7 @@ export const hotelQueryRouter = router({
|
||||
hotelDetailedFacilities: hotelAttributes.detailedFacilities,
|
||||
hotelImages: images,
|
||||
roomCategories,
|
||||
activitiesCard: activities,
|
||||
}
|
||||
}),
|
||||
availability: router({
|
||||
|
||||
Reference in New Issue
Block a user