aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-17 15:38:03 +0000
committerMohamedBassem <me@mbassem.com>2024-03-17 15:38:03 +0000
commit60467f1d7fdc63e8ec3b10ad0d183248cebac4ee (patch)
treed94e78eddab8ea07c74ea4b18e7d0cf551591bc9 /packages
parent19c67633956760096a49275a161f29ca2f6537c0 (diff)
downloadkarakeep-60467f1d7fdc63e8ec3b10ad0d183248cebac4ee.tar.zst
feature(web): A better tags editor using react select with auto complete and auto create
Diffstat (limited to 'packages')
-rw-r--r--packages/trpc/routers/tags.ts29
1 files changed, 27 insertions, 2 deletions
diff --git a/packages/trpc/routers/tags.ts b/packages/trpc/routers/tags.ts
index af11f34c..61b052d9 100644
--- a/packages/trpc/routers/tags.ts
+++ b/packages/trpc/routers/tags.ts
@@ -1,5 +1,5 @@
import { experimental_trpcMiddleware, TRPCError } from "@trpc/server";
-import { and, eq } from "drizzle-orm";
+import { and, count, eq } from "drizzle-orm";
import { z } from "zod";
import { bookmarks, bookmarkTags, tagsOnBookmarks } from "@hoarder/db/schema";
@@ -93,7 +93,32 @@ export const tagsAppRouter = router({
return {
id: res[0].id,
name: res[0].name,
- bookmarks: res.flatMap((t) => t.bookmarkId ? [t.bookmarkId] : []),
+ bookmarks: res.flatMap((t) => (t.bookmarkId ? [t.bookmarkId] : [])),
};
}),
+ list: authedProcedure
+ .output(
+ z.object({
+ tags: z.array(
+ z.object({
+ id: z.string(),
+ name: z.string(),
+ count: z.number(),
+ }),
+ ),
+ }),
+ )
+ .query(async ({ ctx }) => {
+ const tags = await ctx.db
+ .select({
+ id: tagsOnBookmarks.tagId,
+ name: bookmarkTags.name,
+ count: count(),
+ })
+ .from(tagsOnBookmarks)
+ .where(eq(bookmarkTags.userId, ctx.user.id))
+ .groupBy(tagsOnBookmarks.tagId)
+ .innerJoin(bookmarkTags, eq(bookmarkTags.id, tagsOnBookmarks.tagId));
+ return { tags };
+ }),
});