Chore/cleanup after trpc migration * Clean up TODOs * Rename REDEMPTION constant to SEARCH_TYPE_REDEMPTION * Update dependencies Remove unused deps from scandic-web Add missing deps to trpc package * Update self-referencing imports * Remove unused variables from scandic-web env * Fix missing graphql-tag package * Actually fix * Remove unused env var Approved-by: Christian Andolf Approved-by: Linus Flood
30 lines
975 B
TypeScript
30 lines
975 B
TypeScript
import { router } from "../../.."
|
|
import { publicProcedure } from "../../../procedures"
|
|
import { getUidAndContentTypeByPath } from "../../../services/cms/getUidAndContentTypeByPath"
|
|
import { getNonContentstackUrls } from "../metadata/output"
|
|
import { getLanguageSwitcherInput } from "./input"
|
|
import { getUrlsOfAllLanguages } from "./utils"
|
|
|
|
import type { LanguageSwitcherData } from "../../../types/languageSwitcher"
|
|
|
|
export const languageSwitcherQueryRouter = router({
|
|
get: publicProcedure
|
|
.input(getLanguageSwitcherInput)
|
|
.query(async ({ input }) => {
|
|
const { pathName, lang } = input
|
|
const { uid, contentType } = await getUidAndContentTypeByPath(pathName)
|
|
let urls: LanguageSwitcherData | null = null
|
|
|
|
if (!uid || !contentType) {
|
|
urls = getNonContentstackUrls(lang, pathName)
|
|
} else {
|
|
urls = await getUrlsOfAllLanguages(lang, uid, contentType)
|
|
}
|
|
|
|
return {
|
|
lang,
|
|
urls,
|
|
}
|
|
}),
|
|
})
|