Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Apr 16, 2024
1 parent e23ddf4 commit cf6e344
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,3 @@ const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

module.exports = router;

/**
* @route GET /api/comments
* @desc Get all comments
* @access Public
*/
router.get("/", (req, res, next) => {
Comment.find()
.then(comments => {
return res.json({ comments: comments.map(comment => comment.toJSONFor()) });
})
.catch(next);
});

/**
* @route DELETE /api/comments/:comment
* @desc Delete a comment
* @access Public
* @param {string} req.params.comment - The ID of the comment to be deleted
*/
router.delete("/:comment", async (req, res, next) => {
try {
const comment = await Comment.findById(req.comment._id);
if (!comment) {
return res.sendStatus(404);
}
await comment.remove();
return res.sendStatus(204);
} catch (error) {
next(error);
}
});

0 comments on commit cf6e344

Please sign in to comment.