Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor comments API routes and add GET and DELETE routes for comments #22

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions backend/routes/api/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,46 @@
const mongoose = require("mongoose");
const Comment = mongoose.model("Comment");

/**
* Express router for handling comments API endpoints.
* @module routes/api/comments
*/

module.exports = router;

/**
* GET /api/comments
* Retrieves all comments.
* @name GET/api/comments
* @function
* @memberof module:routes/api/comments
* @param {Object} req - Express request object.
* @param {Object} res - Express response object.
* @returns {Object} - JSON response containing the comments.
*/
router.get("/", (req, res) => {
Comment.find()
.then(comments => {
res.json({ comments });
})
.catch(err => console.log(err));
});
Comment on lines +22 to +28

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.

/**
* DELETE /api/comments/:id
* Deletes a comment by its ID.
* @name DELETE/api/comments/:id
* @function
* @memberof module:routes/api/comments
* @param {Object} req - Express request object.
* @param {Object} res - Express response object.
* @returns {Object} - JSON response indicating the success of the deletion.
*/
router.delete("/:id", async (req, res) => {
try {
await Comment.findByIdAndRemove(req.params.id);
res.json({ success: true });
} catch (err) {
console.log(err);
}
});
Comment on lines +40 to +47

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
Loading