adminmate-express-mongoose 1.3.5 → 1.3.6

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.6",
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)) {
@@ -73,10 +73,16 @@ module.exports = _conf => {
73
73
  value: '$count',
74
74
  _id: false
75
75
  }
76
+ },
77
+ {
78
+ $sort: { count: -1 }
79
+ },
80
+ {
81
+ $limit: limit
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();