Distributed cache * cache deleteKey now uses an options object instead of a lonely argument variable fuzzy * merge * remove debug logs and cleanup * cleanup * add fault handling * add fault handling * add pid when logging redis client creation * add identifier when logging redis client creation * cleanup * feat: add redis-api as it's own app * feature: use http wrapper for redis * feat: add the possibility to fallback to unstable_cache * Add error handling if redis cache is unresponsive * add logging for unstable_cache * merge * don't cache errors * fix: metadatabase on branchdeploys * Handle when /en/destinations throws add ErrorBoundary * Add sentry-logging when ErrorBoundary catches exception * Fix error handling for distributed cache * cleanup code * Added Application Insights back * Update generateApiKeys script and remove duplicate * Merge branch 'feature/redis' of bitbucket.org:scandic-swap/web into feature/redis * merge Approved-by: Linus Flood
102 lines
3.0 KiB
TypeScript
102 lines
3.0 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,
|
|
},
|
|
{
|
|
key: generateTag(lang, uid, affix),
|
|
ttl: "max",
|
|
}
|
|
)
|
|
|
|
const result = getPageSettingsSchema.safeParse(response.data)
|
|
|
|
if (!result.success) {
|
|
console.error("Page settings fetch error: ", result.error)
|
|
return null
|
|
}
|
|
|
|
return result.data
|
|
}),
|
|
})
|