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:
@@ -3,37 +3,25 @@ import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
|
||||
import { router } from "../../.."
|
||||
import { notFoundError } from "../../../errors"
|
||||
import {
|
||||
GetDestinationOverviewPage,
|
||||
GetDestinationOverviewPageRefs,
|
||||
} from "../../../graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
|
||||
import { GetDestinationOverviewPage } from "../../../graphql/Query/DestinationOverviewPage/DestinationOverviewPage.graphql"
|
||||
import { request } from "../../../graphql/request"
|
||||
import {
|
||||
contentstackExtendedProcedureUID,
|
||||
serviceProcedure,
|
||||
} from "../../../procedures"
|
||||
import { ApiCountry } from "../../../types/country"
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
generateTag,
|
||||
} from "../../../utils/generateTag"
|
||||
import { generateTag } from "../../../utils/generateTag"
|
||||
import { getCitiesByCountry } from "../../hotels/services/getCitiesByCountry"
|
||||
import { getCountries } from "../../hotels/services/getCountries"
|
||||
import { getHotelIdsByCityId } from "../../hotels/services/getHotelIdsByCityId"
|
||||
import { getCityPageUrls } from "../destinationCityPage/utils"
|
||||
import { getCountryPageUrls } from "../destinationCountryPage/utils"
|
||||
import {
|
||||
destinationOverviewPageRefsSchema,
|
||||
destinationOverviewPageSchema,
|
||||
} from "./output"
|
||||
import { destinationOverviewPageSchema } from "./output"
|
||||
import { getSortedDestinationsByLanguage } from "./utils"
|
||||
|
||||
import type { Country } from "@scandic-hotels/common/constants/country"
|
||||
|
||||
import type {
|
||||
GetDestinationOverviewPageData,
|
||||
GetDestinationOverviewPageRefsSchema,
|
||||
} from "../../../types/destinationOverviewPage"
|
||||
import type { GetDestinationOverviewPageData } from "../../../types/destinationOverviewPage"
|
||||
import type { City, DestinationsData } from "../../../types/destinationsData"
|
||||
import type { TrackingPageData } from "../../types"
|
||||
|
||||
@@ -41,43 +29,7 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
const getDestinationOverviewPageRefsCounter = createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get.refs"
|
||||
)
|
||||
const metricsGetDestinationOverviewPageRefs =
|
||||
getDestinationOverviewPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetDestinationOverviewPageRefs.start()
|
||||
|
||||
const variables = { locale: lang, uid }
|
||||
const refsResponse = await request<GetDestinationOverviewPageRefsSchema>(
|
||||
GetDestinationOverviewPageRefs,
|
||||
variables,
|
||||
{
|
||||
key: generateRefsResponseTag(lang, uid),
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
metricsGetDestinationOverviewPageRefs.noDataError()
|
||||
throw notFoundError({
|
||||
message: "GetDestinationOverviewPageRefs returned no data",
|
||||
errorDetails: variables,
|
||||
})
|
||||
}
|
||||
|
||||
const validatedRefsData = destinationOverviewPageRefsSchema.safeParse(
|
||||
refsResponse.data
|
||||
)
|
||||
|
||||
if (!validatedRefsData.success) {
|
||||
metricsGetDestinationOverviewPageRefs.validationError(
|
||||
validatedRefsData.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetDestinationOverviewPageRefs.success()
|
||||
const cacheKey = generateTag(lang, uid)
|
||||
|
||||
const getDestinationOverviewPageCounter = createCounter(
|
||||
"trpc.contentstack.destinationOverviewPage.get"
|
||||
@@ -87,11 +39,12 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
|
||||
metricsGetDestinationOverviewPage.start()
|
||||
|
||||
const variables = { locale: lang, uid }
|
||||
const response = await request<GetDestinationOverviewPageData>(
|
||||
GetDestinationOverviewPage,
|
||||
variables,
|
||||
{
|
||||
key: generateTag(lang, uid),
|
||||
key: `${cacheKey}:destinationOverviewPage`,
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user