yusuketk 7 лет назад
Родитель
Сommit
1272334fe4
2 измененных файлов с 10 добавлено и 9 удалено
  1. 6 5
      src/server/models/page-tag-relation.js
  2. 4 4
      src/server/routes/tag.js

+ 6 - 5
src/server/models/page-tag-relation.js

@@ -43,13 +43,14 @@ class PageTagRelation {
     const offset = opt.offset || 0;
     const offset = opt.offset || 0;
     const limit = opt.limit || 50;
     const limit = opt.limit || 50;
 
 
-    const list = await this.aggregate()
+    const tags = await this.aggregate()
       .group({ _id: '$relatedTag', count: { $sum: 1 } })
       .group({ _id: '$relatedTag', count: { $sum: 1 } })
-      .sort(sortOpt)
-      .skip(offset)
-      .limit(limit);
+      .sort(sortOpt);
 
 
-    return list;
+    const list = tags.slice(offset, offset + limit);
+    const totalCount = tags.length;
+
+    return { list, totalCount };
   }
   }
 
 
 }
 }

+ 4 - 4
src/server/routes/tag.js

@@ -62,14 +62,14 @@ module.exports = function(crowi, app) {
 
 
     try {
     try {
       // get tag list contains id and count properties
       // get tag list contains id and count properties
-      const list = await PageTagRelation.createTagListWithCount(queryOptions);
-      const ids = list.map((obj) => { return obj._id });
+      const listData = await PageTagRelation.createTagListWithCount(queryOptions);
+      const ids = listData.list.map((obj) => { return obj._id });
 
 
       // get tag documents for add name data to the list
       // get tag documents for add name data to the list
       const tags = await Tag.find({ _id: { $in: ids } });
       const tags = await Tag.find({ _id: { $in: ids } });
 
 
       // add name property
       // add name property
-      result.data = list.map((elm) => {
+      result.data = listData.list.map((elm) => {
         const data = {};
         const data = {};
         const tag = tags.find((tag) => { return (tag.id === elm._id.toString()) });
         const tag = tags.find((tag) => { return (tag.id === elm._id.toString()) });
 
 
@@ -79,7 +79,7 @@ module.exports = function(crowi, app) {
         return data;
         return data;
       });
       });
 
 
-      result.totalCount = await Tag.count();
+      result.totalCount = listData.totalCount;
 
 
       return res.json(ApiResponse.success(result));
       return res.json(ApiResponse.success(result));
     }
     }