adminmate-express-mongoose 1.3.10 → 1.3.11

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.10",
3
+ "version": "1.3.11",
4
4
  "description": "Adminmate Express/Mongoose connector",
5
5
  "author": "Marc Delalonde",
6
6
  "homepage": "http://adminmate.io",
@@ -84,23 +84,29 @@ module.exports = _conf => {
84
84
 
85
85
  const findParams = queriesArray.length ? { $and: queriesArray } : {};
86
86
 
87
- const data = await currentModel
87
+ const findQuery = currentModel
88
88
  .find(findParams)
89
89
  .select(fieldsToFetchSafe)
90
90
  .populate(fieldsToPopulate)
91
91
  .sort(orderSafe)
92
92
  .skip(rowsPerPage * (page - 1))
93
93
  .limit(rowsPerPage)
94
- .lean()
94
+ .lean();
95
+
96
+ const countQuery = queriesArray.length
97
+ ? currentModel.countDocuments(findParams)
98
+ : currentModel.estimatedDocumentCount();
99
+
100
+ const [data, dataCount] = await Promise.all([findQuery, countQuery])
95
101
  .catch(e => {
96
102
  res.status(403).json({ message: e.message });
103
+ return [];
97
104
  });
98
105
 
99
106
  if (!data) {
100
107
  return res.status(403).json();
101
108
  }
102
109
 
103
- const dataCount = await currentModel.countDocuments(findParams);
104
110
  const nbPage = Math.ceil(dataCount / rowsPerPage);
105
111
 
106
112
  // Make ref fields appeared as link in the dashboard