Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
feat: delete comment api added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreesanjay committed Mar 9, 2024
1 parent eb4d2f2 commit 311631a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
53 changes: 28 additions & 25 deletions server/controller/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,30 +638,32 @@ const getReplyCommemts = async (req, res, next) => {
}


// /**
// * @desc rquest for add commment on a discussions
// * @route DELETE /api/community/discussions/comment
// * @access private
// */
// export const deleteComment: RequestHandler = asyncHandler(
// async (req: Request, res: Response, next: NextFunction): Promise<void> => {
// const { id } = req.params;
// if (!id) {
// res.status(400)
// return next(new Error("Invalid comment"));
// }
// const deletedComment = await Comment.findOneAndDelete({ _id: id })
// if (deletedComment) {
// res.status(200).json({
// status: 'ok',
// message: 'comment deleted',
// deletedComment
// })
// } else {
// next(new Error('Internal server error'))
// }
// }
// )
/**
* @desc rquest for add commment on a discussions
* @route DELETE /api/community/discussions/comment
* @access private
*/
const deleteComment = async (req, res, next) => {
try {
const { id } = req.params;
if (!id) {
res.status(400)
throw new Error("Invalid comment");
}
const deletedComment = await Comment.findOneAndDelete({ _id: id })
if (deletedComment) {
res.status(200).json({
status: 'ok',
message: 'comment deleted',
deletedComment
})
} else {
throw new Error('internal server error')
}
} catch (error) {
next(error.message)
}
}


// /**
Expand Down Expand Up @@ -723,5 +725,6 @@ module.exports = {
dislikeDiscussion,
addComment,
getComments,
getReplyCommemts
getReplyCommemts,
deleteComment
}
3 changes: 2 additions & 1 deletion server/routes/communityRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require('express');
const { isLogedIn } = require('../middlewares/authMiddleware');
const router = express.Router();
const { createCommunity, getSuggestions, joinCommunity, acceptJoin, getmyCommunities } = require('../controller/community')
const { createDiscussion, getDiscussions, getRecentDiscussion, deleteDiscussion, likeDiscussion, dislikeDiscussion, addComment, getComments, getReplyCommemts } = require('../controller/discussion')
const { createDiscussion, getDiscussions, getRecentDiscussion, deleteDiscussion, likeDiscussion, dislikeDiscussion, addComment, getComments, getReplyCommemts,deleteComment } = require('../controller/discussion')

router.get('/get-suggestions', isLogedIn, getSuggestions)
router.post('/', isLogedIn, createCommunity)
Expand All @@ -22,5 +22,6 @@ router.put('/discussions/dislike/:id', isLogedIn, dislikeDiscussion)
router.post('/discussions/comment', isLogedIn, addComment)
router.get('/discussions/comment/:id', isLogedIn, getComments)
router.get('/discussions/comment/reply/:id', isLogedIn, getReplyCommemts)
router.delete('/discussions/comment/:id', isLogedIn, deleteComment)

module.exports = router;

0 comments on commit 311631a

Please sign in to comment.