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
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import { router } from "../../.."
|
|
import { GetCollectionPage } from "../../../graphql/Query/CollectionPage/CollectionPage.graphql"
|
|
import { request } from "../../../graphql/request"
|
|
import { contentstackExtendedProcedureUID } from "../../../procedures"
|
|
import { collectionPageSchema } from "./output"
|
|
import {
|
|
fetchCollectionPageRefs,
|
|
generatePageTags,
|
|
validateCollectionPageRefs,
|
|
} from "./utils"
|
|
|
|
import type { GetCollectionPageSchema } from "../../../types/collectionPage"
|
|
import type { TrackingPageData } from "../../types"
|
|
|
|
export const collectionPageQueryRouter = router({
|
|
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
|
const { lang, uid } = ctx
|
|
|
|
const collectionPageRefsData = await fetchCollectionPageRefs(lang, uid)
|
|
|
|
const collectionPageRefs = validateCollectionPageRefs(
|
|
collectionPageRefsData,
|
|
lang,
|
|
uid
|
|
)
|
|
if (!collectionPageRefs) {
|
|
return null
|
|
}
|
|
const tags = generatePageTags(collectionPageRefs, lang)
|
|
|
|
const getCollectionPageCounter = createCounter(
|
|
"trpc.contentstack",
|
|
"collectionPage.get"
|
|
)
|
|
const metricsGetCollectionPage = getCollectionPageCounter.init({
|
|
lang,
|
|
uid,
|
|
})
|
|
|
|
metricsGetCollectionPage.start()
|
|
|
|
const response = await request<GetCollectionPageSchema>(
|
|
GetCollectionPage,
|
|
{ locale: lang, uid },
|
|
{
|
|
key: tags,
|
|
ttl: "max",
|
|
}
|
|
)
|
|
|
|
const collectionPage = collectionPageSchema.safeParse(response.data)
|
|
if (!collectionPage.success) {
|
|
metricsGetCollectionPage.validationError(collectionPage.error)
|
|
return null
|
|
}
|
|
|
|
metricsGetCollectionPage.success()
|
|
|
|
const tracking: TrackingPageData = {
|
|
pageId: collectionPage.data.collection_page.system.uid,
|
|
domainLanguage: lang,
|
|
publishDate: collectionPage.data.collection_page.system.updated_at,
|
|
createDate: collectionPage.data.collection_page.system.created_at,
|
|
channel: "collection-page",
|
|
pageType: "collectionpage",
|
|
pageName: collectionPage.data.trackingProps.url,
|
|
siteSections: collectionPage.data.trackingProps.url,
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
return {
|
|
collectionPage: collectionPage.data.collection_page,
|
|
tracking,
|
|
}
|
|
}),
|
|
})
|