shinoka7 6 лет назад
Родитель
Сommit
9150afe137
2 измененных файлов с 5 добавлено и 4 удалено
  1. 4 2
      src/server/models/comment.js
  2. 1 2
      src/server/routes/comment.js

+ 4 - 2
src/server/models/comment.js

@@ -78,9 +78,11 @@ module.exports = function(crowi) {
     }));
   };
 
-  commentSchema.statics.removeRepliesByCommentId = function(commentId) {
+  commentSchema.methods.removeWithReplies = function(commentId) {
+    const Comment = crowi.model('Comment');
+
     return new Promise(((resolve, reject) => {
-      this.remove({ replyTo: commentId }, (err, done) => {
+      Comment.remove({ $or: [{ replyTo: commentId }, { _id: commentId }] }, (err, done) => {
         if (err) {
           return reject(err);
         }

+ 1 - 2
src/server/routes/comment.js

@@ -174,8 +174,7 @@ module.exports = function(crowi, app) {
         throw new Error('Current user is not accessible to this page.');
       }
 
-      await Comment.removeRepliesByCommentId(commentId);
-      await comment.remove();
+      await comment.removeWithReplies(commentId);
       await Page.updateCommentCount(comment.page);
     }
     catch (err) {