controllers/thoughtController.js
// Delete a thought and remove them from the user
Delete a thought and remove them from the user
Delete a thought and remove them from the user
deleteThought(req, res) {
    Thought.findOneAndRemove({ _id: req.params.thoughtId })
      .then((thought) =>
        !thought
          ? res.status(404).json({ message: "No such thought exists" })
          : User.findOneAndUpdate(
              { thoughts: req.params.thoughtId },
              { $pull: { thoughts: req.params.thoughtId } },
              { new: true }
            )
      )
      .then((user) =>
        !user
          ? res.status(404).json({
              message: "Thought deleted, but no users found",
            })
          : res.json({ message: "Thought successfully deleted" })
      )
      .catch((err) => {
        console.log(err);
        res.status(500).json(err);
      });
  }
deleteThought ( req , res ) { Thought . findOneAndRemove ( { _id : req . params . thoughtId } ) . then ( ( thought ) => ! thought ? res . status ( 404 ) . json ( { message : "No such thought exists" } ) : User . findOneAndUpdate ( { thoughts : req . params . thoughtId } , { $pull : { thoughts : req . params . thoughtId } } , { new : true } ) ) . then ( ( user ) => ! user ? res . status ( 404 ) . json ( { message : "Thought deleted, but no users found" , } ) : res . json ( { message : "Thought successfully deleted" } ) ) . catch ( ( err ) => { console . log ( err ) ; res . status ( 500 ) . json ( err ) ; } ) ; }
Delete a thought and remove them from the user
Delete a thought and remove them from the user