aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/lists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/routers/lists.ts')
-rw-r--r--packages/trpc/routers/lists.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/trpc/routers/lists.ts b/packages/trpc/routers/lists.ts
index 5cab0ac3..d4b56ecf 100644
--- a/packages/trpc/routers/lists.ts
+++ b/packages/trpc/routers/lists.ts
@@ -1,3 +1,4 @@
+import assert from "node:assert";
import { experimental_trpcMiddleware, TRPCError } from "@trpc/server";
import { and, eq } from "drizzle-orm";
import { z } from "zod";
@@ -222,4 +223,23 @@ export const listsAppRouter = router({
return { lists };
}),
+ getListsOfBookmark: authedProcedure
+ .input(z.object({ bookmarkId: z.string() }))
+ .output(
+ z.object({
+ lists: z.array(zBookmarkListSchema),
+ }),
+ )
+ .use(ensureBookmarkOwnership)
+ .query(async ({ input, ctx }) => {
+ const lists = await ctx.db.query.bookmarksInLists.findMany({
+ where: and(eq(bookmarksInLists.bookmarkId, input.bookmarkId)),
+ with: {
+ list: true,
+ },
+ });
+ assert(lists.map((l) => l.list.userId).every((id) => id == ctx.user.id));
+
+ return { lists: lists.map((l) => l.list) };
+ }),
});