feat: Graphql queries and TRPC route setup for Hotel Page Component
This commit is contained in:
7
lib/graphql/Query/HotelPage.graphql
Normal file
7
lib/graphql/Query/HotelPage.graphql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
query GetHotelPage($locale: String!, $uid: String!) {
|
||||||
|
hotel_page(locale: $locale, uid: $uid) {
|
||||||
|
hotel_page_id
|
||||||
|
url
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,4 +33,12 @@ query ResolveEntryByUrl($locale: String!, $url: String!) {
|
|||||||
}
|
}
|
||||||
total
|
total
|
||||||
}
|
}
|
||||||
|
all_hotel_page(where: { url: $url }, locale: $locale) {
|
||||||
|
items {
|
||||||
|
system {
|
||||||
|
...System
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
server/routers/contentstack/hotelPage/index.ts
Normal file
5
server/routers/contentstack/hotelPage/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { mergeRouters } from "@/server/trpc"
|
||||||
|
|
||||||
|
import { hotelPageQueryRouter } from "./query"
|
||||||
|
|
||||||
|
export const hotelPageRouter = mergeRouters(hotelPageQueryRouter)
|
||||||
16
server/routers/contentstack/hotelPage/output.ts
Normal file
16
server/routers/contentstack/hotelPage/output.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const validateHotelPageSchema = z.object({
|
||||||
|
hotel_page: z.object({
|
||||||
|
hotel_page_id: z.string(),
|
||||||
|
title: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
// Will be extended once we introduce more functionality to our entries.
|
||||||
|
export type HotelPageDataRaw = z.infer<typeof validateHotelPageSchema>
|
||||||
|
|
||||||
|
type HotelPageRaw = HotelPageDataRaw["hotel_page"]
|
||||||
|
|
||||||
|
export type HotelPage = HotelPageRaw
|
||||||
35
server/routers/contentstack/hotelPage/query.ts
Normal file
35
server/routers/contentstack/hotelPage/query.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage.graphql"
|
||||||
|
import { request } from "@/lib/graphql/request"
|
||||||
|
import { notFound } from "@/server/errors/trpc"
|
||||||
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||||
|
|
||||||
|
import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
||||||
|
|
||||||
|
export const hotelPageQueryRouter = router({
|
||||||
|
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||||
|
const { lang, uid } = ctx
|
||||||
|
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||||
|
locale: lang,
|
||||||
|
uid,
|
||||||
|
})
|
||||||
|
if (!response.data) {
|
||||||
|
throw notFound(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
const validatedHotelPage = validateHotelPageSchema.safeParse(response.data)
|
||||||
|
|
||||||
|
if (!validatedHotelPage.success) {
|
||||||
|
console.info(
|
||||||
|
`Failed to validate Hotel Page - (uid: ${uid}, lang: ${lang})`
|
||||||
|
)
|
||||||
|
console.error(validatedHotelPage.error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const hotelPage = {
|
||||||
|
...validatedHotelPage.data.hotel_page,
|
||||||
|
} as HotelPage
|
||||||
|
|
||||||
|
return hotelPage
|
||||||
|
}),
|
||||||
|
})
|
||||||
@@ -3,6 +3,7 @@ import { router } from "@/server/trpc"
|
|||||||
import { accountPageRouter } from "./accountPage"
|
import { accountPageRouter } from "./accountPage"
|
||||||
import { baseRouter } from "./base"
|
import { baseRouter } from "./base"
|
||||||
import { breadcrumbsRouter } from "./breadcrumbs"
|
import { breadcrumbsRouter } from "./breadcrumbs"
|
||||||
|
import { hotelPageRouter } from "./hotelPage"
|
||||||
import { languageSwitcherRouter } from "./languageSwitcher"
|
import { languageSwitcherRouter } from "./languageSwitcher"
|
||||||
import { loyaltyPageRouter } from "./loyaltyPage"
|
import { loyaltyPageRouter } from "./loyaltyPage"
|
||||||
import { myPagesRouter } from "./myPages"
|
import { myPagesRouter } from "./myPages"
|
||||||
@@ -11,6 +12,7 @@ export const contentstackRouter = router({
|
|||||||
accountPage: accountPageRouter,
|
accountPage: accountPageRouter,
|
||||||
base: baseRouter,
|
base: baseRouter,
|
||||||
breadcrumbs: breadcrumbsRouter,
|
breadcrumbs: breadcrumbsRouter,
|
||||||
|
hotelPage: hotelPageRouter,
|
||||||
languageSwitcher: languageSwitcherRouter,
|
languageSwitcher: languageSwitcherRouter,
|
||||||
loyaltyPage: loyaltyPageRouter,
|
loyaltyPage: loyaltyPageRouter,
|
||||||
myPages: myPagesRouter,
|
myPages: myPagesRouter,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type StatusParams = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ContentTypeParams = {
|
export type ContentTypeParams = {
|
||||||
contentType: "loyalty-page" | "content-page"
|
contentType: "loyalty-page" | "content-page" | "hotel-page"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ContentTypeWebviewParams = {
|
export type ContentTypeWebviewParams = {
|
||||||
|
|||||||
@@ -17,4 +17,5 @@ export const validateEntryResolveSchema = z.object({
|
|||||||
all_content_page: entryResolveSchema,
|
all_content_page: entryResolveSchema,
|
||||||
all_loyalty_page: entryResolveSchema,
|
all_loyalty_page: entryResolveSchema,
|
||||||
all_current_blocks_page: entryResolveSchema,
|
all_current_blocks_page: entryResolveSchema,
|
||||||
|
all_hotel_page: entryResolveSchema,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user