@azteam/express 1.2.272 → 1.2.274

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": "@azteam/express",
3
- "version": "1.2.272",
3
+ "version": "1.2.274",
4
4
  "main": "src/index.js",
5
5
  "engines": {
6
6
  "node": ">= 12.0.0",
@@ -30,12 +30,11 @@ class AdminController extends Controller {
30
30
  this.guardResponse = options.guardResponse || [];
31
31
  this.allowResponse = options.allowResponse ? [...options.allowResponse, ...ALLOW_FIELDS] : ALLOW_FIELDS;
32
32
 
33
- this.rulesCreate =
34
- {
35
- ...options.rulesCreate,
36
- priority: schemaNumber(true),
37
- status: schemaEnum([0, 1, 2], true),
38
- } || {};
33
+ this.rulesCreate = {
34
+ ...options.rulesCreate,
35
+ priority: schemaNumber(true),
36
+ status: schemaEnum([0, 1, 2], true),
37
+ };
39
38
 
40
39
  this.rulesModify = {
41
40
  isForceModify: schemaBoolean(true),
@@ -45,15 +44,15 @@ class AdminController extends Controller {
45
44
  };
46
45
 
47
46
  if (this.paginateOptions) {
48
- this.paginateOptions.searchFields = [
49
- ...this.paginateOptions.searchFields,
47
+ this.paginateOptions.allowSearchFields = [
48
+ ...this.paginateOptions.allowSearchFields,
50
49
  'status',
51
50
  'created_at_start',
52
51
  'created_at_end',
53
52
  'modified_at_start',
54
53
  'modified_at_end',
55
54
  ];
56
- this.paginateOptions.sortFields = [...this.paginateOptions.sortFields, 'created_at', 'modified_at', 'status'];
55
+ this.paginateOptions.allowSortFields = [...this.paginateOptions.allowSortFields, 'created_at', 'modified_at', 'status'];
57
56
  }
58
57
  }
59
58
 
package/src/Server.js CHANGED
@@ -324,7 +324,7 @@ class Server {
324
324
  throw new ErrorException(NOT_FOUND);
325
325
  });
326
326
 
327
- app.use(function (err, req, res, next) {
327
+ app.use((err, req, res, next) => {
328
328
  const error = errorCatch(err);
329
329
 
330
330
  if (process.env.NODE_ENV === 'development') {
@@ -371,14 +371,14 @@ class Server {
371
371
 
372
372
  return server;
373
373
  }
374
- throw Error('No controllers in use API');
374
+ throw new Error('No controllers in use API');
375
375
  }
376
376
 
377
377
  startSocket(port) {
378
378
  if (!_.isEmpty(this.controllers)) {
379
379
  return this;
380
380
  }
381
- throw Error('No controllers in use SOCKET');
381
+ throw new Error('No controllers in use SOCKET');
382
382
  }
383
383
 
384
384
  setAlertCallback(callback) {
@@ -166,7 +166,7 @@ class SocketServer {
166
166
 
167
167
  return server;
168
168
  }
169
- throw Error('No controllers in use');
169
+ throw new Error('No controllers in use');
170
170
  }
171
171
 
172
172
  setAlertCallback(callback) {
@@ -22,8 +22,9 @@ function omitData(data) {
22
22
  export default function (options = {}) {
23
23
  options = {
24
24
  limit: 20,
25
- searchFields: [],
26
- sortFields: ['created_at', 'modified_at', 'status'],
25
+ allowSearchFields: [],
26
+ allowSortFields: ['created_at', 'modified_at', 'status'],
27
+ allowLimits: [20, 40, 80],
27
28
  ...options,
28
29
  };
29
30
 
@@ -34,15 +35,17 @@ export default function (options = {}) {
34
35
  req.paginate = {
35
36
  limit: options.limit,
36
37
  };
37
- if (req.query.limit) {
38
+ if (req.query.limit && options.allowLimits.includes(req.query.limit)) {
38
39
  req.paginate.limit = Number(req.query.limit);
39
40
  delete req.query.limit;
41
+ } else {
42
+ throw new ErrorException(INVALID, `limit just accept ${options.allowLimits.toString()}`);
40
43
  }
41
44
 
42
45
  req.paginate.page = req.query.page ? Number(req.query.page) : 1;
43
46
  req.paginate.offset = (req.paginate.page - 1) * req.paginate.limit;
44
47
 
45
- if (req.query.sort_by && options.sortFields.includes(req.query.sort_by)) {
48
+ if (req.query.sort_by && options.allowSortFields.includes(req.query.sort_by)) {
46
49
  req.paginate.sort = {
47
50
  [req.query.sort_by]: req.query.sort_type === 'asc' ? 'asc' : 'desc',
48
51
  };
@@ -52,6 +55,10 @@ export default function (options = {}) {
52
55
  delete req.query.sort_type;
53
56
  delete req.query.page;
54
57
 
58
+ if (!options.allowSearchFields.includes(key)) {
59
+ throw new ErrorException(INVALID, `Not exists search ${key}`);
60
+ }
61
+
55
62
  if (req.query.autocomplete) {
56
63
  if (!options.autocompleteField) {
57
64
  throw new ErrorException(INVALID, 'Not exists autocomplete field');
@@ -81,7 +88,7 @@ export default function (options = {}) {
81
88
  };
82
89
  }
83
90
 
84
- if (!options.searchFields.includes(key)) {
91
+ if (!options.allowSearchFields.includes(key)) {
85
92
  throw new ErrorException(INVALID, `Not exists search ${key}`);
86
93
  }
87
94
  });
@@ -9,6 +9,6 @@ export default function (mTimeout = 5) {
9
9
  return next();
10
10
  }
11
11
  }
12
- throw ErrorException(SIGNATURE_FAILED);
12
+ throw new ErrorException(SIGNATURE_FAILED);
13
13
  };
14
14
  }
@@ -51,7 +51,7 @@ export default function (type, rules) {
51
51
  const errors = v.validate(reqData, rules);
52
52
 
53
53
  if (Array.isArray(errors)) {
54
- throw ErrorException(INVALID, errors);
54
+ throw new ErrorException(INVALID, errors);
55
55
  }
56
56
  return next();
57
57
  };
package/src/validate.js CHANGED
@@ -149,9 +149,7 @@ export const rulesSlug = {
149
149
  export const rulesKey = {
150
150
  key: schemaKey(),
151
151
  };
152
- export const rulesPlatformType = {
153
- type: schemaEnum(['web', 'app']),
154
- };
152
+
155
153
  export const rulesMetadata = {
156
154
  metadata_disable: schemaBoolean(true),
157
155
  metadata_title: schemaString(0, 255, true),