diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-05-18 19:12:27 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-05-18 19:12:27 +0000 |
| commit | a5ae67c241d8cdd452acd4d98800ec61740c041f (patch) | |
| tree | f04929b1b27000564d108f25918c6e70fe651fb6 /packages/trpc | |
| parent | 053d1a905ed6cef71151d168351f22b35ddca986 (diff) | |
| download | karakeep-a5ae67c241d8cdd452acd4d98800ec61740c041f.tar.zst | |
feat(api): Expose the endpoint to create a new tag
Diffstat (limited to 'packages/trpc')
| -rw-r--r-- | packages/trpc/routers/tags.ts | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/packages/trpc/routers/tags.ts b/packages/trpc/routers/tags.ts index 7f75c16e..cade4b45 100644 --- a/packages/trpc/routers/tags.ts +++ b/packages/trpc/routers/tags.ts @@ -7,7 +7,9 @@ import { SqliteError } from "@karakeep/db"; import { bookmarkTags, tagsOnBookmarks } from "@karakeep/db/schema"; import { triggerSearchReindex } from "@karakeep/shared/queues"; import { + zCreateTagRequestSchema, zGetTagResponseSchema, + zTagBasicSchema, zUpdateTagRequestSchema, } from "@karakeep/shared/types/tags"; @@ -53,19 +55,8 @@ export const ensureTagOwnership = experimental_trpcMiddleware<{ export const tagsAppRouter = router({ create: authedProcedure - .input( - z.object({ - name: z.string().min(1), // Ensure the name is provided and not empty - }), - ) - .output( - z.object({ - id: z.string(), - name: z.string(), - userId: z.string(), - createdAt: z.date(), - }), - ) + .input(zCreateTagRequestSchema) + .output(zTagBasicSchema) .mutation(async ({ input, ctx }) => { try { const [newTag] = await ctx.db @@ -76,7 +67,10 @@ export const tagsAppRouter = router({ }) .returning(); - return newTag; + return { + id: newTag.id, + name: newTag.name, + }; } catch (e) { if (e instanceof SqliteError && e.code === "SQLITE_CONSTRAINT_UNIQUE") { throw new TRPCError({ @@ -195,14 +189,7 @@ export const tagsAppRouter = router({ }), update: authedProcedure .input(zUpdateTagRequestSchema) - .output( - z.object({ - id: z.string(), - name: z.string(), - userId: z.string(), - createdAt: z.date(), - }), - ) + .output(zTagBasicSchema) .use(ensureTagOwnership) .mutation(async ({ input, ctx }) => { try { @@ -242,7 +229,10 @@ export const tagsAppRouter = router({ console.error("Failed to reindex affected bookmarks", e); } - return res[0]; + return { + id: res[0].id, + name: res[0].name, + }; } catch (e) { if (e instanceof SqliteError) { if (e.code == "SQLITE_CONSTRAINT_UNIQUE") { |
