From 3d495cd16aff9e37a8db27ae4ee88c0fbad93122 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 1 Jul 2024 11:29:28 +0000 Subject: fix: Fix duplicate bookmarks in links with assets --- packages/trpc/routers/bookmarks.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'packages/trpc/routers/bookmarks.ts') diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index edf196bb..d0ffc7d3 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -601,7 +601,11 @@ export const bookmarksAppRouter = router({ }; } - if (row.bookmarkTags) { + if ( + row.bookmarkTags && + // Duplicates may accur because of the join, so we need to make sure we're not adding the same tag twice + !acc[bookmarkId].tags.some((t) => t.id == row.bookmarkTags!.id) + ) { invariant( row.tagsOnBookmarks, "if bookmark tag is set, its many-to-many relation must also be set", -- cgit v1.2.3-70-g09d2