shinoka7 6 سال پیش
والد
کامیت
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) => {
     return new Promise(((resolve, reject) => {
-      this.remove({ replyTo: commentId }, (err, done) => {
+      Comment.remove({ $or: [{ replyTo: commentId }, { _id: commentId }] }, (err, done) => {
         if (err) {
         if (err) {
           return reject(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.');
         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);
       await Page.updateCommentCount(comment.page);
     }
     }
     catch (err) {
     catch (err) {