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( 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, } }), })