sagar4915
sagar4915
TTCTheo's Typesafe Cult
Created by sagar4915 on 4/24/2023 in #questions
"trpc failed on posts.getAll" - unsure what is broken and how to debug it?
Here's my postsRouter: export const postsRouter = createTRPCRouter({ getAll: publicProcedure.query(async ({ ctx }) => { const posts = await ctx.prisma.post.findMany({ take: 100, orderBy: [{ createdAt: "desc" }], }); const users = ( await clerkClient.users.getUserList({ userId: posts.map((post) => post.authorid), limit: 100, }) ).map(filterUserForClient); console.log(users); return posts.map((post) => { const author = users.find((user) => user.id === post.authorid); if (!author || !author.username) throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Author not found", }); return { post, author: { ...author, username: author.username, }, }; }); }),
5 replies