|
|
@ -35,6 +35,8 @@ class CommentController extends SiteController { |
|
|
|
|
|
|
|
router.post('/:commentId/vote', authRequired, this.postVote.bind(this)); |
|
|
|
|
|
|
|
router.get('/:commentId/replies', this.getCommentReplies.bind(this)); |
|
|
|
|
|
|
|
router.delete('/:commentId', |
|
|
|
authRequired, |
|
|
|
limiterService.create(limiterService.config.comment.deleteComment), |
|
|
@ -80,6 +82,31 @@ class CommentController extends SiteController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async getCommentReplies (req, res) { |
|
|
|
const { comment: commentService } = this.dtp.services; |
|
|
|
try { |
|
|
|
const displayList = this.createDisplayList('get-replies'); |
|
|
|
|
|
|
|
Object.assign(res.locals, req.app.locals); |
|
|
|
|
|
|
|
res.locals.pagination = this.getPaginationParameters(req, 20); |
|
|
|
res.locals.comments = await commentService.getReplies(res.locals.comment, res.locals.pagination); |
|
|
|
|
|
|
|
const html = await commentService.renderTemplate('commentList', res.locals); |
|
|
|
|
|
|
|
const replyList = `ul.dtp-reply-list[data-comment-id="${res.locals.comment._id}"]`; |
|
|
|
displayList.addElement(replyList, 'beforeEnd', html); |
|
|
|
|
|
|
|
const replyListContainer = `.dtp-reply-list-container[data-comment-id="${res.locals.comment._id}"]`; |
|
|
|
displayList.removeAttribute(replyListContainer, 'hidden'); |
|
|
|
|
|
|
|
res.status(200).json({ success: true, displayList }); |
|
|
|
} catch (error) { |
|
|
|
res.status(error.statusCode || 500).json({ success: false, message: error.message }); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
async deleteComment (req, res) { |
|
|
|
const { comment: commentService } = this.dtp.services; |
|
|
|
try { |
|
|
|