@azteam/express 1.2.435 → 1.2.437

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,38 @@ 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, selectFields).join(' ');
63
+ } else {
64
+ // req.paginate.select = '_id';
65
+ req.paginate.select = options.allowSelectFields.join(' ');
66
+ }
67
+ }
68
+ delete req.query.select;
69
+ console.log(req.paginate.select);
58
70
  if (!req.query.limit) {
59
- _context.next = 11;
71
+ _context.next = 14;
60
72
  break;
61
73
  }
62
74
  limit = Number(req.query.limit);
63
75
  if (!options.allowLimits.includes(limit)) {
64
- _context.next = 10;
76
+ _context.next = 13;
65
77
  break;
66
78
  }
67
79
  req.paginate.limit = limit;
68
80
  delete req.query.limit;
69
- _context.next = 11;
81
+ _context.next = 14;
70
82
  break;
71
- case 10:
83
+ case 13:
72
84
  throw new _error.ErrorException(_error.INVALID, [{
73
85
  field: 'limit',
74
86
  message: "limit just accept ".concat(options.allowLimits.toString()),
75
87
  expected: options.allowLimits,
76
88
  actual: limit
77
89
  }]);
78
- case 11:
90
+ case 14:
79
91
  req.paginate.page = req.query.page ? Number(req.query.page) : 1;
80
92
  if (req.query.sort_by && options.allowSortFields.includes(req.query.sort_by)) {
81
93
  req.paginate.sort = _defineProperty({}, req.query.sort_by, req.query.sort_type === 'asc' ? 'asc' : 'desc');
@@ -84,25 +96,25 @@ function _default() {
84
96
  delete req.query.sort_type;
85
97
  delete req.query.page;
86
98
  if (!req.query.autocomplete) {
87
- _context.next = 22;
99
+ _context.next = 25;
88
100
  break;
89
101
  }
90
102
  if (options.autocompleteField) {
91
- _context.next = 19;
103
+ _context.next = 22;
92
104
  break;
93
105
  }
94
106
  throw new _error.ErrorException(_error.INVALID, [{
95
107
  field: 'autocomplete',
96
108
  message: 'Not exists autocomplete field'
97
109
  }]);
98
- case 19:
110
+ case 22:
99
111
  req.query = _defineProperty({}, options.autocompleteField, {
100
112
  $regex: req.query.autocomplete,
101
113
  $options: 'i'
102
114
  });
103
- _context.next = 24;
115
+ _context.next = 27;
104
116
  break;
105
- case 22:
117
+ case 25:
106
118
  _lodash["default"].map(req.query, function (value, key) {
107
119
  if (key.endsWith('_start')) {
108
120
  var newKey = key.replace('_start', '');
@@ -133,9 +145,9 @@ function _default() {
133
145
  }
134
146
  });
135
147
  }
136
- case 24:
148
+ case 27:
137
149
  return _context.abrupt("return", next());
138
- case 25:
150
+ case 28:
139
151
  case "end":
140
152
  return _context.stop();
141
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.435",
3
+ "version": "1.2.437",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -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,19 @@ 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(options.allowSelectFields, selectFields).join(' ');
48
+ } else {
49
+ // req.paginate.select = '_id';
50
+ req.paginate.select = options.allowSelectFields.join(' ');
51
+ }
52
+ }
53
+ delete req.query.select;
54
+
55
+ console.log(req.paginate.select);
56
+
43
57
  if (req.query.limit) {
44
58
  const limit = Number(req.query.limit);
45
59
 
@@ -92,6 +92,7 @@ export default function (roles = null, minLevel = USER_LEVEL.USER, opts = {}) {
92
92
  },
93
93
  }),
94
94
  response = await client.post(`${systemURL}/v1/user_positions/is_permission`, {roles: JSON.stringify(roles)});
95
+
95
96
  if (response.success) {
96
97
  return next();
97
98
  }