jcc-express-mvc 1.2.2 → 1.2.4

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": "jcc-express-mvc",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "express mvc structure",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -119,12 +119,10 @@ class Util {
119
119
  try {
120
120
  if (this.classController(callback)) {
121
121
  if (this.isMiddleware()) {
122
- this.app[httpMethod](this.resolvePath(path), [
122
+ return this.app[httpMethod](this.resolvePath(path), [
123
123
  this.middlewares,
124
124
  asyncHandler(this.controller[callback]),
125
125
  ]);
126
-
127
- return (this.middlewares = null);
128
126
  }
129
127
 
130
128
  return this.app[httpMethod](
@@ -133,7 +131,7 @@ class Util {
133
131
  );
134
132
  }
135
133
  if (this.isMiddleware()) {
136
- this.app[httpMethod](this.resolvePath(path), [
134
+ return this.app[httpMethod](this.resolvePath(path), [
137
135
  this.middlewares,
138
136
  asyncHandler(this.validateCallback(callback)),
139
137
  ]);
@@ -14,6 +14,34 @@ class ValidationMethod {
14
14
  : false;
15
15
  }
16
16
 
17
+ /**
18
+ * Validates if a field is required.
19
+ * @param {string} fieldName - The name of the field.
20
+ * @param {object} value - The value of the field.
21
+ * @returns {string|boolean} - Error message if validation fails, otherwise false.
22
+ */
23
+ object(fieldName, value) {
24
+ return typeof value != "object"
25
+ ? `${capitalize(
26
+ fieldName
27
+ )} expected an object but received a ${typeof value}`
28
+ : false;
29
+ }
30
+
31
+ /**
32
+ * Validates if a field is required.
33
+ * @param {string} fieldName - The name of the field.
34
+ * @param {Array} value - The value of the field.
35
+ * @returns {string|boolean} - Error message if validation fails, otherwise false.
36
+ */
37
+ array(fieldName, value) {
38
+ return !Array.isArray(value)
39
+ ? `${capitalize(
40
+ fieldName
41
+ )} expected an array but received a ${typeof value}`
42
+ : false;
43
+ }
44
+
17
45
  /**
18
46
  * Validates if a field meets a minimum length requirement.
19
47
  * @param {string} fieldName - The name of the field.
@@ -271,6 +299,9 @@ class ValidationMethod {
271
299
  return false;
272
300
  }
273
301
 
302
+ next() {
303
+ return false;
304
+ }
274
305
  /**
275
306
  * Validates if a field is a valid MongoDB ObjectId.
276
307
  * @param {string} fieldName - The name of the field being validated.
@@ -84,8 +84,16 @@ exports.rules = async (validation, fieldName, fieldValue, secondValue) => {
84
84
  case "skip":
85
85
  return ValidationMethod.skip();
86
86
 
87
+ case "next":
88
+ return ValidationMethod.next();
89
+
90
+ case "array":
91
+ return ValidationMethod.array(fieldName, fieldValue);
92
+
93
+ case "object":
94
+ return ValidationMethod.object(fieldName, fieldValue);
95
+
87
96
  default:
88
- // return `${validation}() invalid method`;
89
97
  let err = new Error(
90
98
  "validation method",
91
99
  `${validation}() invalid method`
@@ -94,6 +102,7 @@ exports.rules = async (validation, fieldName, fieldValue, secondValue) => {
94
102
  throw err;
95
103
  }
96
104
  } catch (error) {
105
+ console.log(error?.message);
97
106
  let err = new Error("validation error", error);
98
107
  err.validationMethod = error.message;
99
108
  throw err;