Skip to content
Snippets Groups Projects
Commit 47ba8ca3 authored by Morris, George (UG - Computer Science)'s avatar Morris, George (UG - Computer Science)
Browse files

Created the addComment and removeComment functions for adding and deleting commentID's from a post

parent 7e93c013
No related branches found
No related tags found
2 merge requests!8CI/CD,!2Posts service
......@@ -56,9 +56,21 @@ export const likePost = async (req, res) => {
}
export const addComment = async (req, res) => {
const { id, commentId } = req.params;
const post = await Post.findById(id);
post.comments.push(commentId);
await post.save();
return res.status(200).json(post);
}
export const removeComment = async (req, res) => {
const { id, commentId } = req.params;
const post = await Post.findById(id);
const commentIndex = post.comments.findIndex((c) => c === commentId);
post.comments.splice(commentIndex, 1);
await post.save();
return res.status(200).json(post);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment