diff --git a/server/controller/discussion.js b/server/controller/discussion.js index 25ec014..d20137c 100644 --- a/server/controller/discussion.js +++ b/server/controller/discussion.js @@ -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 => { -// 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) + } +} // /** @@ -723,5 +725,6 @@ module.exports = { dislikeDiscussion, addComment, getComments, - getReplyCommemts + getReplyCommemts, + deleteComment } \ No newline at end of file diff --git a/server/routes/communityRoute.js b/server/routes/communityRoute.js index 790e64a..0f6fe64 100644 --- a/server/routes/communityRoute.js +++ b/server/routes/communityRoute.js @@ -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) @@ -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; \ No newline at end of file