-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComment.js
29 lines (26 loc) · 926 Bytes
/
Comment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import lodash from 'lodash';
import CommentModal from '../modals/CommentModal'
class CommentController{
static createComment(req, res){
try{
const comment = lodash.pick(req.body,['comment']);
comment.CreatedBy = req.user.email;
const articleId = req.params.articleId;
const saveComment = CommentModal.saveComment(articleId, comment);
return res.status(201).send({
status: 201,
message: "Comment succesfully posted",
data:{
createdon: saveComment.Createdon,
createdby: saveComment.CreatedBy,
articleTitle: saveComment.article.title,
article: saveComment.article.article,
comment: saveComment.comment
}
});
}catch(error){
return res.status(404).send({status: 404, message: error});
}
}
}
export default CommentController;