Skip to content

Commit

Permalink
fixed reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
chelcie de almeida authored and chelcie de almeida committed Jun 17, 2021
1 parent f7ed1ef commit c41beb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 18 additions & 2 deletions controllers/thought-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,30 @@ const thoughtController = {
// delete reaction

deleteReaction({ params }, res) {
Thought.findOneAndDelete(
Thought.findOneAndUpdate(
{ _id: params.thoughtId },
{ $pull: { reactions: { reactionId: params.reactionId } } },
{ new: true }
)
.then(dbThoughtData => res.json(dbThoughtData))
.catch(err => res.json(err));
}
},

// get all reactions

getAllReactions(req, res) {
Thought.find({})
.populate({
path: 'thoughts',
select: '-__v'
})
.select('-__v')
.then(dbThoughtData => res.json(dbThoughtData))
.catch(err => {
console.log(err);
res.status(400).json(err);
});
}

}

Expand Down
5 changes: 3 additions & 2 deletions routes/api/thought-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ const {
updateThought,
deleteThought,
createReaction,
deleteReaction
deleteReaction,
getAllReactions
} = require('../../controllers/thought-controller')

router.route('/').get(getAllThoughts).post(createThought)

router.route('/:id').get(getThoughtById).put(updateThought).delete(deleteThought)

router.route('/:thoughtId/reactions').post(createReaction)
router.route('/:thoughtId/reactions').post(createReaction).get(getAllReactions)

router.route('/:thoughtId/reactionId').delete(deleteReaction)

Expand Down

0 comments on commit c41beb9

Please sign in to comment.