Answers for "For updated count likes you should send updated count of likes from server"

0

For updated count likes you should send updated count of likes from server

app.post("/index/:id", function(req,res){
  TestData.findById(req.params.id, function(err, theUser){
      if(err){
          console.log(err);
          return res.status(500).send('Something went wrong!'); // You should notify user about any error    
      } else {
          theUser.likes += 1;
          theUser.save(function(err){
          if(err) return res.status(500).send('Something went wrong!');
          return res.send({likes_count: theUser.likes});
          });

      }
  });
});
Posted by: Guest on October-14-2021

Browse Popular Code Answers by Language