From ab88f59842f180ff0ebc1452c5403244b407b8bd Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 1 Feb 2025 15:57:32 +0000 Subject: feat: Add a new modifiedAt field to bookmarks table. Fixes #952 --- packages/trpc/routers/bookmarks.ts | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'packages/trpc') diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 4426ab14..4bf32a08 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -489,19 +489,30 @@ export const bookmarksAppRouter = router({ ) .use(ensureBookmarkOwnership) .mutation(async ({ input, ctx }) => { - const res = await ctx.db - .update(bookmarkTexts) - .set({ - text: input.text, - }) - .where(and(eq(bookmarkTexts.id, input.bookmarkId))) - .returning(); - if (res.length == 0) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "Bookmark not found", - }); - } + await ctx.db.transaction(async (tx) => { + const res = await tx + .update(bookmarkTexts) + .set({ + text: input.text, + }) + .where(and(eq(bookmarkTexts.id, input.bookmarkId))) + .returning(); + if (res.length == 0) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "Bookmark not found", + }); + } + await tx + .update(bookmarks) + .set({ modifiedAt: new Date() }) + .where( + and( + eq(bookmarks.id, input.bookmarkId), + eq(bookmarks.userId, ctx.user.id), + ), + ); + }); await triggerSearchReindex(input.bookmarkId); await triggerWebhook(input.bookmarkId, "edited"); }), -- cgit v1.2.3-70-g09d2