diff options
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index f68d5ada..15ded2bd 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -711,7 +711,7 @@ export const bookmarksAppRouter = router({ ) .use(ensureBookmarkOwnership) .mutation(async ({ input, ctx }) => { - return ctx.db.transaction(async (tx) => { + const res = await ctx.db.transaction(async (tx) => { // Detaches const idsToRemove: string[] = []; if (input.detach.length > 0) { @@ -822,28 +822,32 @@ export const bookmarksAppRouter = router({ ), ); - await triggerRuleEngineOnEvent(input.bookmarkId, [ - ...idsToRemove.map((t) => ({ + return { + bookmarkId: input.bookmarkId, + attached: allIds, + detached: idsToRemove, + }; + }); + + await Promise.allSettled([ + triggerRuleEngineOnEvent(input.bookmarkId, [ + ...res.detached.map((t) => ({ type: "tagRemoved" as const, tagId: t, })), - ...allIds.map((t) => ({ + ...res.attached.map((t) => ({ type: "tagAdded" as const, tagId: t, })), - ]); - await triggerSearchReindex(input.bookmarkId, { + ]), + triggerSearchReindex(input.bookmarkId, { groupId: ctx.user.id, - }); - await triggerWebhook(input.bookmarkId, "edited", ctx.user.id, { + }), + triggerWebhook(input.bookmarkId, "edited", ctx.user.id, { groupId: ctx.user.id, - }); - return { - bookmarkId: input.bookmarkId, - attached: allIds, - detached: idsToRemove, - }; - }); + }), + ]); + return res; }), getBrokenLinks: authedProcedure .output( |
