Has the user liked the post before or not using Sequelize

前端 未结 2 820
南旧
南旧 2021-01-28 07:10

Currently when a user likes a post, that like record gets added to my Likes table with the userId and the postId.

Now, when a user is looking at a post, I want to determi

2条回答
  •  难免孤独
    2021-01-28 08:04

    You don't need to request Like once again, you got all post's likes at your hand:

    for (const post of plainPosts) {
     // check if we have any like among posts' likes that is made by a certain user
     const isLiked = post.Likes.some(x => x.userId === req.user.id);
     const { Post_Images, ...postAttributes } = post;
     ...
    

提交回复
热议问题