Chore/cleanup after trpc migration * Clean up TODOs * Rename REDEMPTION constant to SEARCH_TYPE_REDEMPTION * Update dependencies Remove unused deps from scandic-web Add missing deps to trpc package * Update self-referencing imports * Remove unused variables from scandic-web env * Fix missing graphql-tag package * Actually fix * Remove unused env var Approved-by: Christian Andolf Approved-by: Linus Flood
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import * as Sentry from "@sentry/nextjs"
|
|
|
|
import { router } from "../../.."
|
|
import { PageContentTypeEnum } from "../../../enums/contentType"
|
|
import {
|
|
GetAccountPageSettings,
|
|
GetCampaignOverviewPageSettings,
|
|
GetCampaignPageSettings,
|
|
GetCollectionPageSettings,
|
|
GetContentPageSettings,
|
|
GetCurrentBlocksPageSettings,
|
|
GetDestinationCityPageSettings,
|
|
GetDestinationCountryPageSettings,
|
|
GetDestinationOverviewPageSettings,
|
|
GetHotelPageSettings,
|
|
GetLoyaltyPageSettings,
|
|
GetStartPageSettings,
|
|
} from "../../../graphql/Query/PageSettings.graphql"
|
|
import { request } from "../../../graphql/request"
|
|
import { contentstackBaseProcedure } from "../../../procedures"
|
|
import { langInput } from "../../../utils"
|
|
import { generateTag } from "../../../utils/generateTag"
|
|
import {
|
|
DEFAULT_GET_PAGE_SETTINGS,
|
|
type GetPageSettingsSchema,
|
|
getPageSettingsSchema,
|
|
} from "./output"
|
|
import { affix } from "./utils"
|
|
|
|
export const pageSettingsQueryRouter = router({
|
|
get: contentstackBaseProcedure
|
|
.input(langInput)
|
|
.query(async ({ input, ctx }): Promise<GetPageSettingsSchema> => {
|
|
const { contentType, uid } = ctx
|
|
const lang = input.lang ?? ctx.lang
|
|
|
|
// This condition is to handle 404 page case and booking flow
|
|
if (!contentType || !uid) {
|
|
return DEFAULT_GET_PAGE_SETTINGS
|
|
}
|
|
|
|
const getPageSettingsQuery =
|
|
graphqlQueriesForContentType[contentType as PageContentTypeEnum]
|
|
|
|
if (!getPageSettingsQuery) {
|
|
Sentry.captureMessage(
|
|
`GetPageSettings: No proper Content type defined for '${contentType}'`
|
|
)
|
|
return DEFAULT_GET_PAGE_SETTINGS
|
|
}
|
|
|
|
const response = await request<GetPageSettingsSchema>(
|
|
getPageSettingsQuery,
|
|
{
|
|
uid: uid,
|
|
locale: lang,
|
|
},
|
|
{
|
|
key: generateTag(lang, uid, affix),
|
|
ttl: "max",
|
|
}
|
|
)
|
|
|
|
try {
|
|
const result = getPageSettingsSchema.parse(response.data)
|
|
return result
|
|
} catch (error) {
|
|
Sentry.captureException(error, { extra: { uid, contentType } })
|
|
|
|
return DEFAULT_GET_PAGE_SETTINGS
|
|
}
|
|
}),
|
|
})
|
|
|
|
const graphqlQueriesForContentType: Record<PageContentTypeEnum, any> = {
|
|
[PageContentTypeEnum.accountPage]: GetAccountPageSettings,
|
|
[PageContentTypeEnum.campaignOverviewPage]: GetCampaignOverviewPageSettings,
|
|
[PageContentTypeEnum.campaignPage]: GetCampaignPageSettings,
|
|
[PageContentTypeEnum.collectionPage]: GetCollectionPageSettings,
|
|
[PageContentTypeEnum.contentPage]: GetContentPageSettings,
|
|
[PageContentTypeEnum.currentBlocksPage]: GetCurrentBlocksPageSettings,
|
|
[PageContentTypeEnum.destinationCityPage]: GetDestinationCityPageSettings,
|
|
[PageContentTypeEnum.destinationCountryPage]:
|
|
GetDestinationCountryPageSettings,
|
|
[PageContentTypeEnum.destinationOverviewPage]:
|
|
GetDestinationOverviewPageSettings,
|
|
[PageContentTypeEnum.hotelPage]: GetHotelPageSettings,
|
|
[PageContentTypeEnum.loyaltyPage]: GetLoyaltyPageSettings,
|
|
[PageContentTypeEnum.startPage]: GetStartPageSettings,
|
|
}
|