From f06b0036f644171231a9710bbda660014ee570f9 Mon Sep 17 00:00:00 2001 From: Vahn Gomes Date: Wed, 11 Oct 2023 21:31:51 -0400 Subject: [PATCH] Removed duplicate route --- backend/controllers/CommentController.js | 147 ----------------------- 1 file changed, 147 deletions(-) diff --git a/backend/controllers/CommentController.js b/backend/controllers/CommentController.js index e468c0ea..8d7f77ec 100644 --- a/backend/controllers/CommentController.js +++ b/backend/controllers/CommentController.js @@ -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}: