Parcourir la source

edit method tags.list

yusuketk il y a 7 ans
Parent
commit
d8260babe5
2 fichiers modifiés avec 15 ajouts et 9 suppressions
  1. 2 2
      src/client/js/components/TagsList.jsx
  2. 13 7
      src/server/routes/tag.js

+ 2 - 2
src/client/js/components/TagsList.jsx

@@ -26,8 +26,8 @@ export default class TagsList extends React.Component {
     const offset = (selectPageNumber - 1) * limit;
     const res = await this.props.crowi.apiGet('/tags.list', { limit, offset });
 
-    const totalCount = res.result.totalCount;
-    const tagData = res.result.tags;
+    const totalCount = res.totalCount;
+    const tagData = res.data;
     const activePage = selectPageNumber;
     const paginationNumbers = this.calculatePagination(limit, totalCount, activePage);
 

+ 13 - 7
src/server/routes/tag.js

@@ -43,20 +43,26 @@ module.exports = function(crowi, app) {
     try {
       // get tag list contains id and count properties
       const list = await PageTagRelation.createTagListWithCount(queryOptions);
+      const ids = list.map((obj) => { return obj._id });
 
       // get tag documents for add name data to the list
-      const tags = await Tag.find({ _id: { $in: list } });
+      const tags = await Tag.find({ _id: { $in: ids } });
 
-      // add name data
-      result.tags = list.map((elm) => {
-        const tag = tags.find((tag) => { return (tag.id === String(elm._id)) });
-        elm.name = tag.name;
-        return elm;
+      // add name property
+      result.data = list.map((elm) => {
+        const data = {};
+
+        const tag = tags.find((tag) => { return (tag.id === elm._id.toString()) });
+
+        data._id = elm._id;
+        data.name = tag.name;
+        data.count = elm.count; // the number of related pages
+        return data;
       });
 
       result.totalCount = await Tag.count();
 
-      return res.json(ApiResponse.success({ result }));
+      return res.json(ApiResponse.success(result));
     }
     catch (err) {
       return res.json(ApiResponse.error(err));