zamis 5 лет назад
Родитель
Сommit
1cdf59d2f1
1 измененных файлов с 15 добавлено и 8 удалено
  1. 15 8
      src/server/service/page.js

+ 15 - 8
src/server/service/page.js

@@ -29,25 +29,32 @@ class PageService {
       Revision.find({ path: { $in: pagePaths } }).remove({}),
       Page.find({ _id: { $in: pageIds } }).remove({}),
       Page.find({ path: { $in: pagePaths } }).remove({}),
+      this.removeAllAttachments(pageIds),
     ]);
 
-    // TODO fix remove action of attachments
-    // const hoge = await this.removeAllAttachments(pageIds);
+    // const deleteAttachments = await this.removeAllAttachments(pageIds);
+
     return deleteData;
 
   }
 
-  async removeAllAttachments(pageId) {
+  async removeAllAttachments(pageIds) {
     const Attachment = this.crowi.model('Attachment');
     const { attachmentService } = this.crowi;
 
-    const attachments = await Attachment.find({ page: pageId });
+    const attachments = await Attachment.find({ page: { $in: pageIds } });
 
-    const promises = attachments.map(async(attachment) => {
-      return attachmentService.removeAttachment(attachment._id);
-    });
+    const hoge = await attachmentService.removeAttachment(attachments);
+    console.log('===============');
+    console.log(hoge);
+    console.log('===============');
+
+    return hoge;
+    // const promises = attachments.map(async(attachment) => {
+    //   return attachmentService.removeAttachment(attachment._id);
+    // });
 
-    return Promise.all(promises);
+    // return Promise.all(promises);
   }
 
   async duplicate(page, newPagePath, user) {