@azteam/express 1.2.483 → 1.2.484

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.
@@ -41,7 +41,7 @@ function _default() {
41
41
  var options = _objectSpread({
42
42
  limit: 20,
43
43
  allowSearchFields: [],
44
- allowSortFields: ['created_at', 'modified_at', 'status'],
44
+ allowSortFields: ['id', 'created_at', 'modified_at', 'status'],
45
45
  allowSelectFields: null,
46
46
  allowLimits: [20, 40, 80]
47
47
  }, opts);
@@ -119,28 +119,32 @@ function _default() {
119
119
  break;
120
120
  case 24:
121
121
  _lodash["default"].map(req.query, function (value, key) {
122
- if (key.endsWith('_start')) {
123
- var newKey = key.replace('_start', '');
124
- req.query[newKey] = _objectSpread(_objectSpread({}, req.query[newKey]), {}, {
125
- $gte: value
126
- });
127
- } else if (key.endsWith('_end')) {
128
- var _newKey = key.replace('_end', '');
129
- req.query[_newKey] = _objectSpread(_objectSpread({}, req.query[_newKey]), {}, {
130
- $lte: value
131
- });
132
- } else if (value.includes(',') && key !== 'keywords') {
133
- req.query[key] = {
134
- $in: value.split(',')
135
- };
136
- }
137
- if (!options.allowSearchFields.includes(key)) {
138
- throw new _error.ErrorException(_error.INVALID, [{
139
- field: 'key',
140
- message: "Not exists search ".concat(key),
141
- actual: key,
142
- expected: options.allowSearchFields
143
- }]);
122
+ if (key === 'id') {
123
+ req.query._id = value;
124
+ } else {
125
+ if (key.endsWith('_start')) {
126
+ var newKey = key.replace('_start', '');
127
+ req.query[newKey] = _objectSpread(_objectSpread({}, req.query[newKey]), {}, {
128
+ $gte: value
129
+ });
130
+ } else if (key.endsWith('_end')) {
131
+ var _newKey = key.replace('_end', '');
132
+ req.query[_newKey] = _objectSpread(_objectSpread({}, req.query[_newKey]), {}, {
133
+ $lte: value
134
+ });
135
+ } else if (value.includes(',') && key !== 'keywords') {
136
+ req.query[key] = {
137
+ $in: value.split(',')
138
+ };
139
+ }
140
+ if (!options.allowSearchFields.includes(key)) {
141
+ throw new _error.ErrorException(_error.INVALID, [{
142
+ field: 'key',
143
+ message: "Not exists search ".concat(key),
144
+ actual: key,
145
+ expected: options.allowSearchFields
146
+ }]);
147
+ }
144
148
  }
145
149
  });
146
150
  if (req.query.keywords) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.483",
3
+ "version": "1.2.484",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -27,7 +27,7 @@ export default function (opts = {}) {
27
27
  const options = {
28
28
  limit: 20,
29
29
  allowSearchFields: [],
30
- allowSortFields: ['created_at', 'modified_at', 'status'],
30
+ allowSortFields: ['id', 'created_at', 'modified_at', 'status'],
31
31
  allowSelectFields: null,
32
32
  allowLimits: [20, 40, 80],
33
33
  ...opts,
@@ -100,35 +100,39 @@ export default function (opts = {}) {
100
100
  };
101
101
  } else {
102
102
  _.map(req.query, (value, key) => {
103
- if (key.endsWith('_start')) {
104
- const newKey = key.replace('_start', '');
105
-
106
- req.query[newKey] = {
107
- ...req.query[newKey],
108
- $gte: value,
109
- };
110
- } else if (key.endsWith('_end')) {
111
- const newKey = key.replace('_end', '');
112
-
113
- req.query[newKey] = {
114
- ...req.query[newKey],
115
- $lte: value,
116
- };
117
- } else if (value.includes(',') && key !== 'keywords') {
118
- req.query[key] = {
119
- $in: value.split(','),
120
- };
121
- }
122
-
123
- if (!options.allowSearchFields.includes(key)) {
124
- throw new ErrorException(INVALID, [
125
- {
126
- field: 'key',
127
- message: `Not exists search ${key}`,
128
- actual: key,
129
- expected: options.allowSearchFields,
130
- },
131
- ]);
103
+ if (key === 'id') {
104
+ req.query._id = value;
105
+ } else {
106
+ if (key.endsWith('_start')) {
107
+ const newKey = key.replace('_start', '');
108
+
109
+ req.query[newKey] = {
110
+ ...req.query[newKey],
111
+ $gte: value,
112
+ };
113
+ } else if (key.endsWith('_end')) {
114
+ const newKey = key.replace('_end', '');
115
+
116
+ req.query[newKey] = {
117
+ ...req.query[newKey],
118
+ $lte: value,
119
+ };
120
+ } else if (value.includes(',') && key !== 'keywords') {
121
+ req.query[key] = {
122
+ $in: value.split(','),
123
+ };
124
+ }
125
+
126
+ if (!options.allowSearchFields.includes(key)) {
127
+ throw new ErrorException(INVALID, [
128
+ {
129
+ field: 'key',
130
+ message: `Not exists search ${key}`,
131
+ actual: key,
132
+ expected: options.allowSearchFields,
133
+ },
134
+ ]);
135
+ }
132
136
  }
133
137
  });
134
138