jcc-express-mvc 1.2.0 → 1.2.2

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.0",
3
+ "version": "1.2.2",
4
4
  "description": "express mvc structure",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,7 +10,6 @@ class TinkerNode extends Database {
10
10
 
11
11
  validatedInput(input) {
12
12
  const sanitizedInputData = this.sanitizedInput(input);
13
- console.log(sanitizedInputData);
14
13
  if (sanitizedInputData !== input) {
15
14
  // Input contains disallowed characters, reject it
16
15
  throw new Error("Input contains disallowed characters.");
@@ -36,6 +36,24 @@ class Util {
36
36
  this.middlewares = middlewares;
37
37
  }
38
38
 
39
+ /**
40
+ * Checks if the callback is a fuction or an array .
41
+ * @param {function|array} callback - Route callback.
42
+ */
43
+ validateCallback(callback) {
44
+ if (typeof callback === "function") {
45
+ return callback;
46
+ }
47
+ if (Array.isArray(callback) && callback.length === 2) {
48
+ const [controller, method] = callback;
49
+ return controller[method];
50
+ }
51
+
52
+ throw new Error(
53
+ `Callback expect to be a function or an array. but got ${callback} instead`
54
+ );
55
+ }
56
+
39
57
  /**
40
58
  * Resolves the path based on the route prefix and base path.
41
59
  * @param {string} path - The path to resolve.
@@ -117,12 +135,12 @@ class Util {
117
135
  if (this.isMiddleware()) {
118
136
  this.app[httpMethod](this.resolvePath(path), [
119
137
  this.middlewares,
120
- asyncHandler(callback),
138
+ asyncHandler(this.validateCallback(callback)),
121
139
  ]);
122
140
  }
123
141
  return this.app[httpMethod](
124
142
  this.resolvePath(path),
125
- asyncHandler(callback)
143
+ asyncHandler(this.validateCallback(callback))
126
144
  );
127
145
  } catch (error) {
128
146
  throw new Error(error?.message);