adminmate-express-mongoose 1.3.6 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminmate-express-mongoose",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Adminmate Express/Mongoose connector",
5
5
  "author": "Marc Delalonde",
6
6
  "homepage": "http://adminmate.io",
@@ -67,18 +67,18 @@ module.exports = _conf => {
67
67
  count: data.operation === 'avg' ? { $avg: _value } : { $sum: _value },
68
68
  }
69
69
  },
70
+ {
71
+ $sort: { count: -1 }
72
+ },
73
+ {
74
+ $limit: limit
75
+ },
70
76
  {
71
77
  $project: {
72
78
  key: '$_id',
73
79
  value: '$count',
74
80
  _id: false
75
81
  }
76
- },
77
- {
78
- $sort: { count: -1 }
79
- },
80
- {
81
- $limit: limit
82
82
  }
83
83
  ]);
84
84
  // .limit(limit)
@@ -13,7 +13,7 @@ module.exports = _conf => {
13
13
  const inlineActions = req.headers['am-inline-actions'] || [];
14
14
  const fieldsToSearchIn = req.query.search_in_fields || [];
15
15
  const page = parseInt(req.query.page || 1);
16
- const nbItemPerPage = 10;
16
+ const rowsPerPage = parseInt(req.query.rows || 10);
17
17
  const defaultOrdering = [ ['_id', 'DESC'] ];
18
18
  const order = req.query.order || null;
19
19
 
@@ -89,8 +89,8 @@ module.exports = _conf => {
89
89
  .select(fieldsToFetchSafe)
90
90
  .populate(fieldsToPopulate)
91
91
  .sort(orderSafe)
92
- .skip(nbItemPerPage * (page - 1))
93
- .limit(nbItemPerPage)
92
+ .skip(rowsPerPage * (page - 1))
93
+ .limit(rowsPerPage)
94
94
  .lean()
95
95
  .catch(e => {
96
96
  res.status(403).json({ message: e.message });
@@ -101,7 +101,7 @@ module.exports = _conf => {
101
101
  }
102
102
 
103
103
  const dataCount = await currentModel.countDocuments(findParams);
104
- const nbPage = Math.ceil(dataCount / nbItemPerPage);
104
+ const nbPage = Math.ceil(dataCount / rowsPerPage);
105
105
 
106
106
  // Make ref fields appeared as link in the dashboard
107
107
  const formattedData = data.map(item => {
@@ -123,7 +123,8 @@ module.exports = _conf => {
123
123
  count: dataCount,
124
124
  pagination: {
125
125
  current: page,
126
- count: nbPage
126
+ count: nbPage,
127
+ rows_per_page: rowsPerPage
127
128
  }
128
129
  });
129
130
  };