Skip to content

Commit

Permalink
Removed duplicate route
Browse files Browse the repository at this point in the history
  • Loading branch information
Codycody31 committed Oct 12, 2023
1 parent db20812 commit f06b003
Showing 1 changed file with 0 additions and 147 deletions.
147 changes: 0 additions & 147 deletions backend/controllers/CommentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,153 +315,6 @@ router.post("/post/:postId", authenticateJWT, async (req, res) => {
}
});

/**
* @swagger
* /api/v1/comments/{commentId}:
* put:
* tags:
* - Comments
* summary: Update a comment
* description: Update a specific comment
* produces:
* - application/json
* security:
* - BearerAuth: []
* parameters:
* - name: commentId
* in: path
* required: true
* description: ID of the comment to update
* schema:
* $ref: '#/components/schemas/ObjectId'
* requestBody:
* description: Comment details
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* comment:
* type: string
* responses:
* 200:
* description: Successfully updated comment
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: success
* code:
* type: integer
* example: 200
* message:
* type: string
* example: Successfully updated comment
* data:
* $ref: '#/components/schemas/Comment'
* 400:
* description: Comment does not exist or invalid comment provided
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* code:
* type: integer
* example: 400
* message:
* type: string
* example: Comment does not exist or invalid comment provided
* data:
* type: null
* 500:
* description: An error occurred while updating the comment
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* code:
* type: integer
* example: 500
* message:
* type: string
* example: An error occurred while updating the comment
* data:
* type: null
*/
router.put("/:commentId", authenticateJWT, async (req, res) => {
// Params
const comment = req.params.commentId;
const { newComment } = req.body;

// Verify comment exists
const commentExists = await Comment.exists({
_id: comment,
user: req.user._id,
});
if (!commentExists) {
return res.json({
status: "error",
code: 400,
message:
"Comment does not exist or you do not have permission to update it.",
data: null,
});
}

// Validate comment
if (!newComment) {
return res.json({
status: "error",
code: 400,
message: "Comment is required.",
data: null,
});
} else if (newComment.length < 3 || newComment.length > 255) {
return res.json({
status: "error",
code: 400,
message: "Comment must be between 3 and 255 characters.",
data: null,
});
}

// Update the comment
try {
const updatedComment = await Comment.updateOne(
{ _id: comment },
{ comment: newComment }
);

// Return the comment
res.json({
status: "success",
code: 200,
message: "Successfully updated comment.",
data: updatedComment,
});
} catch (error) {
console.error(error);
res.json({
status: "error",
code: 500,
message: "An error occurred while updating the comment.",
data: null,
});
}
});

/**
* @swagger
* /api/v1/comments/{commentId}:
Expand Down

0 comments on commit f06b003

Please sign in to comment.