Skip to content

Commit 02e80c0

Browse files
chore: this works but I hate it (#1055)
Co-authored-by: Niall Maher <nialljoemaher@gmail.com>
1 parent 953918d commit 02e80c0

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

server/api/router/post.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,16 @@ export const postRouter = createTRPCRouter({
218218
eq(like.postId, postId),
219219
eq(like.userId, ctx.session?.user?.id),
220220
),
221-
);
222-
await tx
223-
.update(post)
224-
.set({
225-
likes: decrement(post.likes),
226-
})
227-
.where(eq(post.id, postId));
221+
)
222+
.returning();
223+
if (res.length !== 0) {
224+
await tx
225+
.update(post)
226+
.set({
227+
likes: decrement(post.likes),
228+
})
229+
.where(eq(post.id, postId));
230+
}
228231
});
229232

230233
return res;

0 commit comments

Comments
 (0)