Skip to content

Commit

Permalink
feat: Add DELETE endpoint for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OnFreund committed May 3, 2024
1 parent 9234a0c commit 93efa3f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@ const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

module.exports = router;

router.get("/", (req, res) => {
Comment.find()
.then((comments) => {
res.json(comments);
})
.catch((err) => {
console.log(err);
});
}
);
// copilot, implement a delete endpoint for comments
router.delete("/:id", async (req, res) => {
try {
/**
* Represents a comment object.
* @typedef {Object} Comment
* @property {string} id - The unique identifier of the comment.
* @property {string} content - The content of the comment.
* @property {string} author - The author of the comment.
* @property {Date} createdAt - The date and time when the comment was created.
* @property {Date} updatedAt - The date and time when the comment was last updated.
*/
const comment = await Comment.findByIdAndDelete(req.params.id);
res.json(comment);
} catch (err) {
console.log(err);
}
});

0 comments on commit 93efa3f

Please sign in to comment.