diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-02-01 15:57:32 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-02-01 15:57:32 +0000 |
| commit | ab88f59842f180ff0ebc1452c5403244b407b8bd (patch) | |
| tree | f0eb98f7e774a84a16dc0e2938df93adf94a415d /packages/trpc | |
| parent | 76f4e352b601713ab109b25128e93bdb90200ac1 (diff) | |
| download | karakeep-ab88f59842f180ff0ebc1452c5403244b407b8bd.tar.zst | |
feat: Add a new modifiedAt field to bookmarks table. Fixes #952
Diffstat (limited to 'packages/trpc')
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 37 |
1 files changed, 24 insertions, 13 deletions
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"); }), |
