Kaynağa Gözat

success to delete Activity document

kaori 4 yıl önce
ebeveyn
işleme
2bf952452c

+ 5 - 3
packages/app/src/server/models/activity.ts

@@ -120,8 +120,8 @@ activitySchema.statics.createByPageComment = function(comment) {
    * @param {Comment} comment
    * @param {Comment} comment
    * @return {Promise}
    * @return {Promise}
    */
    */
-activitySchema.statics.removeByPageCommentDelete = function(comment) {
-  const parameters = {
+activitySchema.statics.removeByPageCommentDelete = async function(comment) {
+  const parameters = await {
     user: comment.creator,
     user: comment.creator,
     targetModel: ActivityDefine.MODEL_PAGE,
     targetModel: ActivityDefine.MODEL_PAGE,
     target: comment.page,
     target: comment.page,
@@ -130,7 +130,9 @@ activitySchema.statics.removeByPageCommentDelete = function(comment) {
     action: ActivityDefine.ACTION_COMMENT,
     action: ActivityDefine.ACTION_COMMENT,
   };
   };
 
 
-  return this.removeByParameters(parameters);
+  await this.removeByParameters(parameters);
+
+  return;
 };
 };
 
 
 /**
 /**

+ 3 - 1
packages/app/src/server/models/comment.js

@@ -115,10 +115,12 @@ module.exports = function(crowi) {
     const commentEvent = crowi.event('comment');
     const commentEvent = crowi.event('comment');
 
 
     await commentEvent.emit('remove', comment);
     await commentEvent.emit('remove', comment);
-    return Comment.remove({
+
+    await Comment.remove({
       $or: (
       $or: (
         [{ replyTo: this._id }, { _id: this._id }]),
         [{ replyTo: this._id }, { _id: this._id }]),
     });
     });
+    return;
   };
   };
 
 
 
 

+ 1 - 1
packages/app/src/server/routes/comment.js

@@ -439,7 +439,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.removeWithReplies();
+      await comment.removeWithReplies(comment);
       await Page.updateCommentCount(comment.page);
       await Page.updateCommentCount(comment.page);
     }
     }
     catch (err) {
     catch (err) {

+ 9 - 1
packages/app/src/server/service/in-app-notification.ts

@@ -25,6 +25,7 @@ class InAppNotificationService {
     this.initCommentEvent();
     this.initCommentEvent();
   }
   }
 
 
+
   initCommentEvent(): void {
   initCommentEvent(): void {
     // create
     // create
     this.commentEvent.on('create', async(savedComment) => {
     this.commentEvent.on('create', async(savedComment) => {
@@ -50,8 +51,15 @@ class InAppNotificationService {
     });
     });
 
 
     // remove
     // remove
-    this.commentEvent.on('remove', (commentData) => {
+    this.commentEvent.on('remove', async(comment) => {
       this.commentEvent.onRemove();
       this.commentEvent.onRemove();
+
+      try {
+        await Activity.removeByPageCommentDelete(comment);
+      }
+      catch (err) {
+        logger.error(err);
+      }
     });
     });
 
 
   }
   }