@gieo/express 1.0.3 → 1.0.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/dist/index.js CHANGED
@@ -169,4 +169,6 @@ var ExpressPlus = /** @class */ (function () {
169
169
  };
170
170
  return ExpressPlus;
171
171
  }());
172
+ // ✅ Export cho cả ES Module và CommonJS
172
173
  exports.default = ExpressPlus;
174
+ module.exports = ExpressPlus;
package/dist/test.js CHANGED
@@ -35,42 +35,73 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __rest = (this && this.__rest) || function (s, e) {
39
+ var t = {};
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
+ t[p] = s[p];
42
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
+ t[p[i]] = s[p[i]];
46
+ }
47
+ return t;
48
+ };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  var index_1 = require("./index");
40
51
  var utils_1 = require("@gieo/utils");
41
52
  var app = new index_1.default();
42
53
  app.post("/calc", function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
43
- var _a, a, b, op, result;
54
+ var _a, op, numbers, values, result;
44
55
  return __generator(this, function (_b) {
45
56
  switch (_b.label) {
46
57
  case 0: return [4 /*yield*/, req.getBody()];
47
58
  case 1:
48
- _a = _b.sent(), a = _a.a, b = _a.b, op = _a.op;
49
- switch (op) {
50
- case "sum":
51
- result = (0, utils_1.sum)(a, b);
52
- break;
53
- case "sub":
54
- result = (0, utils_1.sub)(a, b);
55
- break;
56
- case "mul":
57
- result = (0, utils_1.mul)(a, b);
58
- break;
59
- case "div":
60
- result = (0, utils_1.div)(a, b);
61
- break;
62
- default:
63
- return [2 /*return*/, res.status(400).json({
64
- statusCode: 400,
65
- success: false,
66
- message: "Invalid operator",
67
- })];
59
+ _a = _b.sent(), op = _a.op, numbers = __rest(_a, ["op"]);
60
+ values = Object.values(numbers)
61
+ .map(Number)
62
+ .filter(function (v) { return !isNaN(v); });
63
+ if (values.length < 2) {
64
+ return [2 /*return*/, res.status(400).json({
65
+ statusCode: 400,
66
+ success: false,
67
+ message: "Need at least two numeric values",
68
+ })];
68
69
  }
69
- return [2 /*return*/, res.status(200).json({
70
- statusCode: 200,
71
- success: true,
72
- result: result,
73
- })];
70
+ try {
71
+ switch (op) {
72
+ case "sum":
73
+ result = utils_1.sum.apply(void 0, values);
74
+ break;
75
+ case "sub":
76
+ result = utils_1.sub.apply(void 0, values);
77
+ break;
78
+ case "mul":
79
+ result = utils_1.mul.apply(void 0, values);
80
+ break;
81
+ case "div":
82
+ result = utils_1.div.apply(void 0, values);
83
+ break;
84
+ default:
85
+ return [2 /*return*/, res.status(400).json({
86
+ statusCode: 400,
87
+ success: false,
88
+ message: "Invalid operator",
89
+ })];
90
+ }
91
+ return [2 /*return*/, res.status(200).json({
92
+ statusCode: 200,
93
+ success: true,
94
+ result: result,
95
+ })];
96
+ }
97
+ catch (err) {
98
+ return [2 /*return*/, res.status(500).json({
99
+ statusCode: 500,
100
+ success: false,
101
+ message: err.message,
102
+ })];
103
+ }
104
+ return [2 /*return*/];
74
105
  }
75
106
  });
76
107
  }); });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@gieo/express",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/test.js",
6
6
  "keywords": [],
7
7
  "author": "",
8
8
  "license": "ISC",
package/src/index.ts CHANGED
@@ -23,7 +23,7 @@ interface Route {
23
23
  handler: Handler;
24
24
  }
25
25
 
26
- export default class ExpressPlus {
26
+ class ExpressPlus {
27
27
  private routes: Record<Method, Route[]> = {
28
28
  GET: [],
29
29
  POST: [],
@@ -132,3 +132,7 @@ export default class ExpressPlus {
132
132
  server.listen(port, callback);
133
133
  }
134
134
  }
135
+
136
+ // ✅ Export cho cả ES Module và CommonJS
137
+ export default ExpressPlus;
138
+ module.exports = ExpressPlus;
package/src/test.ts CHANGED
@@ -3,35 +3,56 @@ import { sum, sub, mul, div } from "@gieo/utils";
3
3
  const app = new ExpressPlus();
4
4
 
5
5
  app.post("/calc", async (req, res) => {
6
- const { a, b, op } = await req.getBody();
6
+ const { op, ...numbers } = await req.getBody();
7
7
 
8
- let result: number;
9
- switch (op) {
10
- case "sum":
11
- result = sum(a, b);
12
- break;
13
- case "sub":
14
- result = sub(a, b);
15
- break;
16
- case "mul":
17
- result = mul(a, b);
18
- break;
19
- case "div":
20
- result = div(a, b);
21
- break;
22
- default:
23
- return res.status(400).json({
24
- statusCode: 400,
25
- success: false,
26
- message: "Invalid operator",
27
- });
8
+ // Lấy tất cả giá trị số từ body
9
+ const values = Object.values(numbers)
10
+ .map(Number)
11
+ .filter((v) => !isNaN(v));
12
+
13
+ if (values.length < 2) {
14
+ return res.status(400).json({
15
+ statusCode: 400,
16
+ success: false,
17
+ message: "Need at least two numeric values",
18
+ });
28
19
  }
29
20
 
30
- return res.status(200).json({
31
- statusCode: 200,
32
- success: true,
33
- result,
34
- });
21
+ let result: number;
22
+ try {
23
+ switch (op) {
24
+ case "sum":
25
+ result = sum(...values);
26
+ break;
27
+ case "sub":
28
+ result = sub(...values);
29
+ break;
30
+ case "mul":
31
+ result = mul(...values);
32
+ break;
33
+ case "div":
34
+ result = div(...values);
35
+ break;
36
+ default:
37
+ return res.status(400).json({
38
+ statusCode: 400,
39
+ success: false,
40
+ message: "Invalid operator",
41
+ });
42
+ }
43
+
44
+ return res.status(200).json({
45
+ statusCode: 200,
46
+ success: true,
47
+ result,
48
+ });
49
+ } catch (err: any) {
50
+ return res.status(500).json({
51
+ statusCode: 500,
52
+ success: false,
53
+ message: err.message,
54
+ });
55
+ }
35
56
  });
36
57
 
37
58
  // Các route cơ bản