adminmate-express-mongoose 1.3.4 → 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.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Adminmate Express/Mongoose connector",
|
|
5
5
|
"author": "Marc Delalonde",
|
|
6
6
|
"homepage": "http://adminmate.io",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"url": "https://github.com/Adminmate/adminmate-express-mongoose.git"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"adminmate-express-core": "~1.2.
|
|
26
|
+
"adminmate-express-core": "~1.2.3",
|
|
27
27
|
"joi": "^17.6.0",
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"moment": "^2.29.1",
|
|
@@ -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();
|
|
@@ -10,6 +10,7 @@ module.exports = _conf => {
|
|
|
10
10
|
const filters = req.query.filters;
|
|
11
11
|
const fieldsToFetch = req.headers['am-model-fields'] || [];
|
|
12
12
|
const refFields = req.headers['am-ref-fields'] || {};
|
|
13
|
+
const inlineActions = req.headers['am-inline-actions'] || [];
|
|
13
14
|
const fieldsToSearchIn = req.query.search_in_fields || [];
|
|
14
15
|
const page = parseInt(req.query.page || 1);
|
|
15
16
|
const nbItemPerPage = 10;
|
|
@@ -21,6 +22,9 @@ module.exports = _conf => {
|
|
|
21
22
|
return res.status(403).json({ message: 'Invalid request' });
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
// Model actions
|
|
26
|
+
const currentModelActions = fnHelper.getModelActions(modelName);
|
|
27
|
+
|
|
24
28
|
// Get model properties
|
|
25
29
|
const keys = fnHelper.getModelProperties(currentModel);
|
|
26
30
|
|
|
@@ -104,6 +108,16 @@ module.exports = _conf => {
|
|
|
104
108
|
return fnHelper.refFields(item, fieldsToPopulate);
|
|
105
109
|
});
|
|
106
110
|
|
|
111
|
+
// Inline actions button
|
|
112
|
+
const _inlineActions = currentModelActions.filter(action => inlineActions.includes(action.code));
|
|
113
|
+
if (_inlineActions.length) {
|
|
114
|
+
formattedData.forEach(item => {
|
|
115
|
+
item._am_inline_actions = _inlineActions
|
|
116
|
+
.filter(action => typeof action.filter === 'undefined' || action.filter(item))
|
|
117
|
+
.map(action => action.code);
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
107
121
|
res.json({
|
|
108
122
|
data: formattedData,
|
|
109
123
|
count: dataCount,
|
package/src/helpers/functions.js
CHANGED
|
@@ -434,6 +434,15 @@ module.exports = _conf => {
|
|
|
434
434
|
return currentModel.segments;
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
+
const getModelActions = modelCode => {
|
|
438
|
+
const currentModel = getModel(modelCode);
|
|
439
|
+
if (!currentModel) {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return currentModel.actions || [];
|
|
444
|
+
};
|
|
445
|
+
|
|
437
446
|
const getModelSegment = (modelCode, segmentCode) => {
|
|
438
447
|
const currentModel = getModel(modelCode);
|
|
439
448
|
if (!currentModel || !currentModel.segments || currentModel.segments.length === 0) {
|
|
@@ -498,6 +507,7 @@ module.exports = _conf => {
|
|
|
498
507
|
validateOrderStructure,
|
|
499
508
|
getModelSegment,
|
|
500
509
|
getModelSegments,
|
|
510
|
+
getModelActions,
|
|
501
511
|
getModelObject,
|
|
502
512
|
getModelAssociations,
|
|
503
513
|
getModelPrimaryKeys,
|