35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
|
import { request } from "@/lib/graphql/request"
|
|
import { badRequestError } from "@/server/errors/trpc"
|
|
import { publicProcedure, router } from "@/server/trpc"
|
|
|
|
import { getConfigInput } from "./input"
|
|
import { type ContactConfigData, validateContactConfigSchema } from "./output"
|
|
|
|
export const contactConfigQueryRouter = router({
|
|
get: publicProcedure.input(getConfigInput).query(async ({ input }) => {
|
|
try {
|
|
const contactConfig = await request<ContactConfigData>(GetContactConfig, {
|
|
locale: input.lang,
|
|
})
|
|
|
|
if (!contactConfig.data) {
|
|
throw badRequestError()
|
|
}
|
|
|
|
const validatedContactConfigConfig =
|
|
validateContactConfigSchema.safeParse(contactConfig.data)
|
|
|
|
if (!validatedContactConfigConfig.success) {
|
|
console.error(validatedContactConfigConfig.error)
|
|
throw badRequestError()
|
|
}
|
|
|
|
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
|
} catch (e) {
|
|
console.log(e)
|
|
throw badRequestError()
|
|
}
|
|
}),
|
|
})
|