Jelajahi Sumber

clean code in page.js service

zamis 5 tahun lalu
induk
melakukan
057c5d3b2e
1 mengubah file dengan 5 tambahan dan 12 penghapusan
  1. 5 12
      src/server/service/page.js

+ 5 - 12
src/server/service/page.js

@@ -23,6 +23,10 @@ class PageService {
     const PageTagRelation = this.crowi.model('PageTagRelation');
     const PageTagRelation = this.crowi.model('PageTagRelation');
     const ShareLink = this.crowi.model('ShareLink');
     const ShareLink = this.crowi.model('ShareLink');
     const Revision = this.crowi.model('Revision');
     const Revision = this.crowi.model('Revision');
+    const Attachment = this.crowi.model('Attachment');
+
+    const { attachmentService } = this.crowi;
+    const attachments = await Attachment.find({ page: pageIds });
 
 
     return Promise.all([
     return Promise.all([
       Bookmark.find({ page: { $in: pageIds } }).remove({}),
       Bookmark.find({ page: { $in: pageIds } }).remove({}),
@@ -32,21 +36,10 @@ class PageService {
       Revision.find({ path: { $in: pagePaths } }).remove({}),
       Revision.find({ path: { $in: pagePaths } }).remove({}),
       Page.find({ _id: { $in: pageIds } }).remove({}),
       Page.find({ _id: { $in: pageIds } }).remove({}),
       Page.find({ path: { $in: pagePaths } }).remove({}),
       Page.find({ path: { $in: pagePaths } }).remove({}),
-      this.removeAllAttachments(pageIds),
+      attachmentService.removeAllAttachments(attachments),
     ]);
     ]);
   }
   }
 
 
-  async removeAllAttachments(pageIds) {
-    const Attachment = this.crowi.model('Attachment');
-    const { attachmentService } = this.crowi;
-    const attachments = await Attachment.find({ page: pageIds });
-
-    if (attachments.length > 0) {
-      return attachmentService.removeAttachment(attachments);
-    }
-    return;
-  }
-
   async duplicate(page, newPagePath, user, isRecursively) {
   async duplicate(page, newPagePath, user, isRecursively) {
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
     const PageTagRelation = mongoose.model('PageTagRelation');
     const PageTagRelation = mongoose.model('PageTagRelation');