adminmate-express-mongoose 1.3.5 → 1.3.7

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.5",
3
+ "version": "1.3.7",
4
4
  "description": "Adminmate Express/Mongoose connector",
5
5
  "author": "Marc Delalonde",
6
6
  "homepage": "http://adminmate.io",
@@ -16,7 +16,7 @@ module.exports = _conf => {
16
16
  then: Joi.string().required(),
17
17
  otherwise: Joi.string()
18
18
  }),
19
- limit: Joi.number().optional(),
19
+ limit: Joi.alternatives().try(Joi.string(), Joi.number()).optional(),
20
20
  filters: Joi.object({
21
21
  operator: Joi.string().valid('and', 'or').required(),
22
22
  list: Joi.array().required()
@@ -39,7 +39,7 @@ module.exports = _conf => {
39
39
  }
40
40
 
41
41
  // Default limit
42
- let limit = data.limit || 10;
42
+ let limit = parseInt(data.limit) || 10;
43
43
 
44
44
  let _value = 1;
45
45
  if (data.relationship_field && ['sum', 'avg'].includes(data.relationship_operation)) {
@@ -67,6 +67,12 @@ 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',
@@ -74,9 +80,9 @@ module.exports = _conf => {
74
80
  _id: false
75
81
  }
76
82
  }
77
- ])
78
- .limit(limit)
79
- .sort({ value: -1 });
83
+ ]);
84
+ // .limit(limit)
85
+ // .sort({ value: -1 });
80
86
 
81
87
  const parentIds = repartitionData.map(d => d.key);
82
88
  const parentData = await currentModel.find({ _id: parentIds }).select(data.field).lean();