Explorar el Código

server side deletion

shinoka7 hace 6 años
padre
commit
abcbf9297e

+ 0 - 6
src/client/js/components/PageComments.jsx

@@ -74,12 +74,6 @@ class PageComments extends React.Component {
 
   deleteComment() {
     const comment = this.state.commentToDelete;
-    const comments = this.props.commentContainer.state.comments;
-    comments.forEach((reply) => {
-      if (reply.replyTo === comment._id) {
-        this.props.commentContainer.deleteComment(reply);
-      }
-    });
 
     this.props.commentContainer.deleteComment(comment)
       .then(() => {

+ 11 - 0
src/server/models/comment.js

@@ -78,6 +78,17 @@ module.exports = function(crowi) {
     }));
   };
 
+  commentSchema.statics.removeRepliesByCommentId = function(commentId) {
+    return new Promise(((resolve, reject) => {
+      this.remove({ replyTo: commentId }, (err, done) => {
+        if (err) {
+          return reject(err);
+        }
+        resolve(done);
+      });
+    }));
+  };
+
   /**
    * post save hook
    */

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

@@ -174,6 +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 Page.updateCommentCount(comment.page);
     }