router.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { t, publicProcedure, router } from "./trpc";
  2. import prisma from "@/lib/db";
  3. import { z } from "zod";
  4. export const appRouter = router({
  5. ping: publicProcedure.query(async () => {
  6. return { hello: "world" };
  7. }),
  8. org: {
  9. bySlug: publicProcedure
  10. .input(z.object({ mode: z.string() }))
  11. .query(async ({ input: { mode } }) => {
  12. if (!mode) return { mail: "", name: "" };
  13. const res = await fetch(
  14. "https://api.edu.cocorobo.cn/edu/admin/selectorganize",
  15. {
  16. method: "POST",
  17. body: JSON.stringify({ mode }),
  18. headers: {
  19. "Content-Type": "application/json",
  20. },
  21. }
  22. );
  23. const resJson = await res.json();
  24. const { mail, name } = resJson?.[0]?.[0];
  25. return { mail, name };
  26. }),
  27. },
  28. flowModel: {
  29. byId: publicProcedure
  30. .input(
  31. z.object({
  32. multiAgentId: z.string(),
  33. })
  34. )
  35. .query(async ({ input: { multiAgentId } }) => {
  36. const record = await prisma.muti_agent_list.findUnique({
  37. where: { id: multiAgentId },
  38. });
  39. if (!record) return null;
  40. return { ...record, content: JSON.parse(record.content!) };
  41. }),
  42. },
  43. // ...
  44. });
  45. // Export type router type signature,
  46. // NOT the router itself.
  47. export type AppRouter = typeof appRouter;