feat(SW-2863): Move contentstack router to trpc package * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package Approved-by: Linus Flood
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
import { notFound } from "@scandic-hotels/trpc/errors"
|
|
import { contentstackExtendedProcedureUID } from "@scandic-hotels/trpc/procedures"
|
|
|
|
import { router } from "../../.."
|
|
import { GetHotelPage } from "../../../graphql/Query/HotelPage/HotelPage.graphql"
|
|
import { request } from "../../../graphql/request"
|
|
import { generateTag } from "../../../utils/generateTag"
|
|
import { hotelPageSchema } from "./output"
|
|
|
|
import type { GetHotelPageData } from "../../../types/hotelPage"
|
|
|
|
export const hotelPageQueryRouter = router({
|
|
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
|
const { lang, uid } = ctx
|
|
|
|
const getHotelPageCounter = createCounter(
|
|
"trpc.contentstack",
|
|
"hotelPage.get"
|
|
)
|
|
const metricsGetHotelPage = getHotelPageCounter.init({ lang, uid })
|
|
|
|
metricsGetHotelPage.start()
|
|
|
|
const response = await request<GetHotelPageData>(
|
|
GetHotelPage,
|
|
{
|
|
locale: lang,
|
|
uid,
|
|
},
|
|
{
|
|
key: generateTag(lang, uid),
|
|
ttl: "max",
|
|
}
|
|
)
|
|
if (!response.data) {
|
|
const notFoundError = notFound(response)
|
|
metricsGetHotelPage.noDataError()
|
|
throw notFoundError
|
|
}
|
|
|
|
const validatedHotelPage = hotelPageSchema.safeParse(response.data)
|
|
|
|
if (!validatedHotelPage.success) {
|
|
metricsGetHotelPage.validationError(validatedHotelPage.error)
|
|
return null
|
|
}
|
|
|
|
metricsGetHotelPage.success()
|
|
|
|
return validatedHotelPage.data.hotel_page
|
|
}),
|
|
})
|