Merged in feat/rework-contentstack (pull request #3493)
Feat(SW-3708): refactor contentstack fetching (removing all refs) and cache invalidation * Remove all REFS * Revalidate correct language * PR fixes * PR fixes * Throw when errors from contentstack api Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -2,67 +2,21 @@ import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
|
||||
import { router } from "../../.."
|
||||
import { notFoundError } from "../../../errors"
|
||||
import {
|
||||
GetDestinationCityPage,
|
||||
GetDestinationCityPageRefs,
|
||||
} from "../../../graphql/Query/DestinationCityPage/DestinationCityPage.graphql"
|
||||
import { GetDestinationCityPage } from "../../../graphql/Query/DestinationCityPage/DestinationCityPage.graphql"
|
||||
import { request } from "../../../graphql/request"
|
||||
import { contentStackUidWithServiceProcedure } from "../../../procedures"
|
||||
import { generateRefsResponseTag } from "../../../utils/generateTag"
|
||||
import { generateTag } from "../../../utils/generateTag"
|
||||
import { getCityByCityIdentifier } from "../../hotels/services/getCityByCityIdentifier"
|
||||
import {
|
||||
destinationCityPageRefsSchema,
|
||||
destinationCityPageSchema,
|
||||
} from "./output"
|
||||
import { generatePageTags } from "./utils"
|
||||
import { destinationCityPageSchema } from "./output"
|
||||
|
||||
import type {
|
||||
GetDestinationCityPageData,
|
||||
GetDestinationCityPageRefsSchema,
|
||||
} from "../../../types/destinationCityPage"
|
||||
import type { GetDestinationCityPageData } from "../../../types/destinationCityPage"
|
||||
import type { TrackingPageData } from "../../types"
|
||||
|
||||
export const destinationCityPageQueryRouter = router({
|
||||
get: contentStackUidWithServiceProcedure.query(async ({ ctx }) => {
|
||||
const { lang, uid, serviceToken } = ctx
|
||||
|
||||
const getDestinationCityPageRefsCounter = createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get.refs"
|
||||
)
|
||||
const metricsGetDestinationCityPageRefs =
|
||||
getDestinationCityPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationCityPageRefs.start()
|
||||
|
||||
const variables = { locale: lang, uid }
|
||||
const refsResponse = await request<GetDestinationCityPageRefsSchema>(
|
||||
GetDestinationCityPageRefs,
|
||||
variables,
|
||||
{
|
||||
key: generateRefsResponseTag(lang, uid),
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
metricsGetDestinationCityPageRefs.noDataError()
|
||||
throw notFoundError({
|
||||
message: "GetDestinationCityPageRefs returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedRefsData = destinationCityPageRefsSchema.safeParse(
|
||||
refsResponse.data
|
||||
)
|
||||
if (!validatedRefsData.success) {
|
||||
metricsGetDestinationCityPageRefs.validationError(validatedRefsData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetDestinationCityPageRefs.success()
|
||||
|
||||
const tags = generatePageTags(validatedRefsData.data, lang)
|
||||
const cacheKey = generateTag(lang, uid)
|
||||
|
||||
const getDestinationCityPageCounter = createCounter(
|
||||
"trpc.contentstack.destinationCityPage.get"
|
||||
@@ -74,11 +28,12 @@ export const destinationCityPageQueryRouter = router({
|
||||
|
||||
metricsGetDestinationCityPage.start()
|
||||
|
||||
const variables = { locale: lang, uid }
|
||||
const response = await request<GetDestinationCityPageData>(
|
||||
GetDestinationCityPage,
|
||||
variables,
|
||||
{
|
||||
key: tags,
|
||||
key: `${cacheKey}:destinationCityPage`,
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user