104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import {
|
|
GetAccountPageSettings,
|
|
GetCollectionPageSettings,
|
|
GetContentPageSettings,
|
|
GetCurrentBlocksPageSettings,
|
|
GetDestinationCityPageSettings,
|
|
GetDestinationCountryPageSettings,
|
|
GetDestinationOverviewPageSettings,
|
|
GetHotelPageSettings,
|
|
GetLoyaltyPageSettings,
|
|
GetStartPageSettings,
|
|
} from "@/lib/graphql/Query/PageSettings.graphql"
|
|
import { request } from "@/lib/graphql/request"
|
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
|
import { langInput } from "@/server/utils"
|
|
|
|
import { generateTag } from "@/utils/generateTag"
|
|
|
|
import { type GetPageSettingsSchema, getPageSettingsSchema } from "./output"
|
|
import { affix } from "./utils"
|
|
|
|
import { PageContentTypeEnum } from "@/types/requests/contentType"
|
|
|
|
export const pageSettingsQueryRouter = router({
|
|
get: contentstackBaseProcedure
|
|
.input(langInput)
|
|
.query(async ({ input, ctx }) => {
|
|
const { contentType, uid } = ctx
|
|
const lang = input.lang ?? ctx.lang
|
|
|
|
// This condition is to handle 404 page case and booking flow
|
|
if (!contentType || !uid) {
|
|
console.log("No proper params defined: ", contentType, uid)
|
|
return null
|
|
}
|
|
|
|
let GetPageSettings = ""
|
|
|
|
switch (contentType) {
|
|
case PageContentTypeEnum.accountPage:
|
|
GetPageSettings = GetAccountPageSettings
|
|
break
|
|
case PageContentTypeEnum.collectionPage:
|
|
GetPageSettings = GetCollectionPageSettings
|
|
break
|
|
case PageContentTypeEnum.contentPage:
|
|
GetPageSettings = GetContentPageSettings
|
|
break
|
|
case PageContentTypeEnum.currentBlocksPage:
|
|
GetPageSettings = GetCurrentBlocksPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationCityPage:
|
|
GetPageSettings = GetDestinationCityPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationCountryPage:
|
|
GetPageSettings = GetDestinationCountryPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationOverviewPage:
|
|
GetPageSettings = GetDestinationOverviewPageSettings
|
|
break
|
|
case PageContentTypeEnum.hotelPage:
|
|
GetPageSettings = GetHotelPageSettings
|
|
break
|
|
case PageContentTypeEnum.loyaltyPage:
|
|
GetPageSettings = GetLoyaltyPageSettings
|
|
break
|
|
case PageContentTypeEnum.startPage:
|
|
GetPageSettings = GetStartPageSettings
|
|
break
|
|
}
|
|
|
|
if (!GetPageSettings) {
|
|
console.error(
|
|
"[pageSettings] No proper Content type defined: ",
|
|
contentType
|
|
)
|
|
return null
|
|
}
|
|
|
|
const response = await request<GetPageSettingsSchema>(
|
|
GetPageSettings,
|
|
{
|
|
uid: uid,
|
|
locale: lang,
|
|
},
|
|
{
|
|
cache: "force-cache",
|
|
next: {
|
|
tags: [generateTag(lang, uid, affix)],
|
|
},
|
|
}
|
|
)
|
|
|
|
const result = getPageSettingsSchema.safeParse(response.data)
|
|
|
|
if (!result.success) {
|
|
console.error("Page settings fetch error: ", result.error)
|
|
return null
|
|
}
|
|
|
|
return result.data
|
|
}),
|
|
})
|