@azteam/express 1.2.228 → 1.2.231

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.228",
3
+ "version": "1.2.231",
4
4
  "main": "src/index.js",
5
5
  "engines": {
6
6
  "node": ">= 12.0.0",
@@ -41,42 +41,43 @@ export default function (options = {}) {
41
41
  req.paginate.page = req.query.page ? Number(req.query.page) : 1;
42
42
  req.paginate.offset = (req.paginate.page - 1) * req.paginate.limit;
43
43
 
44
- delete req.query.page;
45
-
46
44
  if (req.query.sort_by && options.sortFields.includes(req.query.sort_by)) {
47
45
  req.paginate.sort = {
48
46
  [req.query.sort_by]: req.query.sort_type === 'asc' ? 'asc' : 'desc',
49
47
  };
50
-
51
- delete req.query.sort_by;
52
- delete req.query.sort_type;
48
+ } else if (options.sortFields.length > 0) {
49
+ const sortBy = options.sortFields[0];
50
+ req.paginate.sort = {
51
+ [sortBy]: 'asc',
52
+ };
53
53
  }
54
54
 
55
- for (const key in req.query) {
56
- if (req.query.hasOwnProperty(key)) {
57
- const value = req.query[key];
58
-
59
- if (key.endsWith('_start')) {
60
- const newKey = key.replace('_start', '');
61
-
62
- req.query[newKey] = {
63
- ...req.query[newKey],
64
- $gte: value,
65
- };
66
- } else if (key.endsWith('_end')) {
67
- const newKey = key.replace('_end', '');
55
+ delete req.query.sort_by;
56
+ delete req.query.sort_type;
57
+ delete req.query.page;
68
58
 
69
- req.query[newKey] = {
70
- ...req.query[newKey],
71
- $lte: value,
72
- };
73
- }
59
+ _.map(req.query, (value, key) => {
60
+ if (key.endsWith('_start')) {
61
+ const newKey = key.replace('_start', '');
62
+
63
+ req.query[newKey] = {
64
+ ...req.query[newKey],
65
+ $gte: value,
66
+ };
67
+ } else if (key.endsWith('_end')) {
68
+ const newKey = key.replace('_end', '');
69
+
70
+ req.query[newKey] = {
71
+ ...req.query[newKey],
72
+ $lte: value,
73
+ };
74
+ }
74
75
 
75
- if (!options.searchFields.includes(key)) {
76
- delete req.query[key];
77
- }
76
+ if (!options.searchFields.includes(key)) {
77
+ delete req.query[key];
78
78
  }
79
- }
79
+ });
80
+
80
81
  if (req.query.keywords) {
81
82
  const arrKeywords = _.words(req.query.keywords);
82
83
  const keywords = `"${arrKeywords.join('" "')}"`;
package/src/validate.js CHANGED
@@ -94,6 +94,10 @@ export const schemaVersion = (optional = false) => ({
94
94
  max: 300,
95
95
  optional,
96
96
  });
97
+ export const schemaArray = (optional = false) => ({
98
+ type: 'array',
99
+ optional,
100
+ });
97
101
  export const schemaJSON = (optional = false) => ({
98
102
  type: 'json',
99
103
  optional,