@azteam/express 1.2.273 → 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.273",
3
+ "version": "1.2.274",
4
4
  "main": "src/index.js",
5
5
  "engines": {
6
6
  "node": ">= 12.0.0",
@@ -44,15 +44,15 @@ class AdminController extends Controller {
44
44
  };
45
45
 
46
46
  if (this.paginateOptions) {
47
- this.paginateOptions.searchFields = [
48
- ...this.paginateOptions.searchFields,
47
+ this.paginateOptions.allowSearchFields = [
48
+ ...this.paginateOptions.allowSearchFields,
49
49
  'status',
50
50
  'created_at_start',
51
51
  'created_at_end',
52
52
  'modified_at_start',
53
53
  'modified_at_end',
54
54
  ];
55
- this.paginateOptions.sortFields = [...this.paginateOptions.sortFields, 'created_at', 'modified_at', 'status'];
55
+ this.paginateOptions.allowSortFields = [...this.paginateOptions.allowSortFields, 'created_at', 'modified_at', 'status'];
56
56
  }
57
57
  }
58
58
 
@@ -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
  });