@azteam/express 1.2.436 → 1.2.438
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.
|
@@ -42,11 +42,12 @@ function _default() {
|
|
|
42
42
|
limit: 20,
|
|
43
43
|
allowSearchFields: [],
|
|
44
44
|
allowSortFields: ['created_at', 'modified_at', 'status'],
|
|
45
|
+
allowSelectFields: null,
|
|
45
46
|
allowLimits: [20, 40, 80]
|
|
46
47
|
}, opts);
|
|
47
48
|
return /*#__PURE__*/function () {
|
|
48
49
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
|
|
49
|
-
var limit, keywords;
|
|
50
|
+
var selectFields, limit, keywords;
|
|
50
51
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
51
52
|
while (1) switch (_context.prev = _context.next) {
|
|
52
53
|
case 0:
|
|
@@ -55,27 +56,39 @@ function _default() {
|
|
|
55
56
|
req.paginate = {
|
|
56
57
|
limit: options.limit
|
|
57
58
|
};
|
|
59
|
+
if (options.allowSelectFields) {
|
|
60
|
+
selectFields = req.query.select ? req.query.select.split(',') : [];
|
|
61
|
+
if (selectFields.length > 0) {
|
|
62
|
+
req.paginate.select = _lodash["default"].intersection(options.allowSelectFields, _lodash["default"].map(selectFields, function (field) {
|
|
63
|
+
return _lodash["default"].trim(field);
|
|
64
|
+
})).join(' ');
|
|
65
|
+
} else {
|
|
66
|
+
// req.paginate.select = '_id';
|
|
67
|
+
req.paginate.select = options.allowSelectFields.join(' ');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
delete req.query.select;
|
|
58
71
|
if (!req.query.limit) {
|
|
59
|
-
_context.next =
|
|
72
|
+
_context.next = 13;
|
|
60
73
|
break;
|
|
61
74
|
}
|
|
62
75
|
limit = Number(req.query.limit);
|
|
63
76
|
if (!options.allowLimits.includes(limit)) {
|
|
64
|
-
_context.next =
|
|
77
|
+
_context.next = 12;
|
|
65
78
|
break;
|
|
66
79
|
}
|
|
67
80
|
req.paginate.limit = limit;
|
|
68
81
|
delete req.query.limit;
|
|
69
|
-
_context.next =
|
|
82
|
+
_context.next = 13;
|
|
70
83
|
break;
|
|
71
|
-
case
|
|
84
|
+
case 12:
|
|
72
85
|
throw new _error.ErrorException(_error.INVALID, [{
|
|
73
86
|
field: 'limit',
|
|
74
87
|
message: "limit just accept ".concat(options.allowLimits.toString()),
|
|
75
88
|
expected: options.allowLimits,
|
|
76
89
|
actual: limit
|
|
77
90
|
}]);
|
|
78
|
-
case
|
|
91
|
+
case 13:
|
|
79
92
|
req.paginate.page = req.query.page ? Number(req.query.page) : 1;
|
|
80
93
|
if (req.query.sort_by && options.allowSortFields.includes(req.query.sort_by)) {
|
|
81
94
|
req.paginate.sort = _defineProperty({}, req.query.sort_by, req.query.sort_type === 'asc' ? 'asc' : 'desc');
|
|
@@ -84,25 +97,25 @@ function _default() {
|
|
|
84
97
|
delete req.query.sort_type;
|
|
85
98
|
delete req.query.page;
|
|
86
99
|
if (!req.query.autocomplete) {
|
|
87
|
-
_context.next =
|
|
100
|
+
_context.next = 24;
|
|
88
101
|
break;
|
|
89
102
|
}
|
|
90
103
|
if (options.autocompleteField) {
|
|
91
|
-
_context.next =
|
|
104
|
+
_context.next = 21;
|
|
92
105
|
break;
|
|
93
106
|
}
|
|
94
107
|
throw new _error.ErrorException(_error.INVALID, [{
|
|
95
108
|
field: 'autocomplete',
|
|
96
109
|
message: 'Not exists autocomplete field'
|
|
97
110
|
}]);
|
|
98
|
-
case
|
|
111
|
+
case 21:
|
|
99
112
|
req.query = _defineProperty({}, options.autocompleteField, {
|
|
100
113
|
$regex: req.query.autocomplete,
|
|
101
114
|
$options: 'i'
|
|
102
115
|
});
|
|
103
|
-
_context.next =
|
|
116
|
+
_context.next = 26;
|
|
104
117
|
break;
|
|
105
|
-
case
|
|
118
|
+
case 24:
|
|
106
119
|
_lodash["default"].map(req.query, function (value, key) {
|
|
107
120
|
if (key.endsWith('_start')) {
|
|
108
121
|
var newKey = key.replace('_start', '');
|
|
@@ -133,9 +146,9 @@ function _default() {
|
|
|
133
146
|
}
|
|
134
147
|
});
|
|
135
148
|
}
|
|
136
|
-
case
|
|
149
|
+
case 26:
|
|
137
150
|
return _context.abrupt("return", next());
|
|
138
|
-
case
|
|
151
|
+
case 27:
|
|
139
152
|
case "end":
|
|
140
153
|
return _context.stop();
|
|
141
154
|
}
|
|
@@ -123,7 +123,7 @@ function _default() {
|
|
|
123
123
|
return _context.abrupt("return", next());
|
|
124
124
|
case 38:
|
|
125
125
|
if (!(req.user.level >= minLevel)) {
|
|
126
|
-
_context.next =
|
|
126
|
+
_context.next = 45;
|
|
127
127
|
break;
|
|
128
128
|
}
|
|
129
129
|
_client = new _httpClient["default"]({
|
|
@@ -139,15 +139,14 @@ function _default() {
|
|
|
139
139
|
});
|
|
140
140
|
case 42:
|
|
141
141
|
_response = _context.sent;
|
|
142
|
-
console.log(_response);
|
|
143
142
|
if (!_response.success) {
|
|
144
|
-
_context.next =
|
|
143
|
+
_context.next = 45;
|
|
145
144
|
break;
|
|
146
145
|
}
|
|
147
146
|
return _context.abrupt("return", next());
|
|
148
|
-
case
|
|
147
|
+
case 45:
|
|
149
148
|
throw new _error.ErrorException(_error.PERMISSION);
|
|
150
|
-
case
|
|
149
|
+
case 46:
|
|
151
150
|
case "end":
|
|
152
151
|
return _context.stop();
|
|
153
152
|
}
|
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ export default function (opts = {}) {
|
|
|
28
28
|
limit: 20,
|
|
29
29
|
allowSearchFields: [],
|
|
30
30
|
allowSortFields: ['created_at', 'modified_at', 'status'],
|
|
31
|
+
allowSelectFields: null,
|
|
31
32
|
allowLimits: [20, 40, 80],
|
|
32
33
|
...opts,
|
|
33
34
|
};
|
|
@@ -40,6 +41,20 @@ export default function (opts = {}) {
|
|
|
40
41
|
limit: options.limit,
|
|
41
42
|
};
|
|
42
43
|
|
|
44
|
+
if (options.allowSelectFields) {
|
|
45
|
+
const selectFields = req.query.select ? req.query.select.split(',') : [];
|
|
46
|
+
if (selectFields.length > 0) {
|
|
47
|
+
req.paginate.select = _.intersection(
|
|
48
|
+
options.allowSelectFields,
|
|
49
|
+
_.map(selectFields, (field) => _.trim(field))
|
|
50
|
+
).join(' ');
|
|
51
|
+
} else {
|
|
52
|
+
// req.paginate.select = '_id';
|
|
53
|
+
req.paginate.select = options.allowSelectFields.join(' ');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
delete req.query.select;
|
|
57
|
+
|
|
43
58
|
if (req.query.limit) {
|
|
44
59
|
const limit = Number(req.query.limit);
|
|
45
60
|
|
|
@@ -93,8 +93,6 @@ export default function (roles = null, minLevel = USER_LEVEL.USER, opts = {}) {
|
|
|
93
93
|
}),
|
|
94
94
|
response = await client.post(`${systemURL}/v1/user_positions/is_permission`, {roles: JSON.stringify(roles)});
|
|
95
95
|
|
|
96
|
-
console.log(response);
|
|
97
|
-
|
|
98
96
|
if (response.success) {
|
|
99
97
|
return next();
|
|
100
98
|
}
|