Files
web/packages/trpc/lib/routers/contentstack/profilingConsent/query.ts
Joakim Jäderberg 8b94540d19 Merged in chore/redirect-counter (pull request #3302)
Counter name is now searchable and add counter for redirects

* refactor: createCounter() only takes one argument, the name of the counter. Makes it easier to search for

* feat: add counter when we do a redirect from redirect-service


Approved-by: Linus Flood
2025-12-08 10:24:05 +00:00

61 lines
1.7 KiB
TypeScript

import { createCounter } from "@scandic-hotels/common/telemetry"
import { router } from "../../.."
import { notFound } from "../../../errors"
import { GetProfilingConsent } from "../../../graphql/Query/ProfilingConsent.graphql"
import { request } from "../../../graphql/request"
import { contentstackBaseProcedure } from "../../../procedures"
import { langInput } from "../../../utils"
import { profilingConsentSchema } from "./output"
import type { GetProfilingConsentData } from "../../../types/profilingConsent"
export const profilingConsentQueryRouter = router({
get: contentstackBaseProcedure
.input(langInput.optional())
.query(async ({ input, ctx }) => {
const lang = input?.lang ?? ctx.lang
const tag = `${lang}:profiling_consent`
const getProfilingConsentCounter = createCounter(
"trpc.contentstack.profilingConsent.get"
)
const metricsGetProfilingConsent = getProfilingConsentCounter.init({
lang,
})
metricsGetProfilingConsent.start()
const response = await request<GetProfilingConsentData>(
GetProfilingConsent,
{
locale: lang,
},
{
key: tag,
ttl: "max",
}
)
if (!response.data) {
const notFoundError = notFound(response)
metricsGetProfilingConsent.noDataError()
throw notFoundError
}
const validatedResponse = profilingConsentSchema.safeParse(response.data)
if (!validatedResponse.success) {
metricsGetProfilingConsent.validationError(validatedResponse.error)
return null
}
const profiling_consent = validatedResponse.data
metricsGetProfilingConsent.success()
return {
profiling_consent,
}
}),
})