c2-http 1.0.104 → 1.0.105

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.
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const body_parser_1 = __importDefault(require("body-parser"));
7
- const moment_1 = __importDefault(require("moment"));
7
+ // import moment from "moment";
8
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
8
9
  class MiddlewareBody {
9
10
  config(expressApplication) {
10
11
  expressApplication.use(body_parser_1.default.json({ limit: "5mb" }));
@@ -12,19 +13,22 @@ class MiddlewareBody {
12
13
  expressApplication.use(body_parser_1.default.text({ limit: "5mb" }));
13
14
  expressApplication.use((request, response, next) => {
14
15
  if (request.body && typeof request.body === "object") {
15
- this.convertDates(request.body);
16
+ this.convertDates(request);
16
17
  }
17
18
  next();
18
19
  });
19
20
  }
20
- convertDates(obj) {
21
- for (const key in obj) {
22
- if (obj.hasOwnProperty(key)) {
21
+ convertDates(request) {
22
+ for (const key in request.body) {
23
+ if (request.body.hasOwnProperty(key)) {
23
24
  if (key.endsWith("Date") || key.endsWith("DateTime")) {
24
- obj[key] = moment_1.default.utc(obj[key]);
25
+ const tz = request.headers["timezone"] || "America/Sao_Paulo"; // fallback padrão
26
+ // interpreta como GMT-3
27
+ request.body[key] = moment_timezone_1.default.tz(request.body[key], "YYYY-MM-DD", tz);
28
+ // obj[key] = moment.utc(obj[key]);
25
29
  }
26
- else if (typeof obj[key] === "object" && obj[key] !== null) {
27
- this.convertDates(obj[key]);
30
+ else if (typeof request.body[key] === "object" && request.body[key] !== null) {
31
+ this.convertDates(request.body[key]);
28
32
  }
29
33
  }
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.104",
3
+ "version": "1.0.105",
4
4
  "description": "Biblioteca Typescript para API NodeJS",
5
5
  "repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
6
6
  "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",
@@ -34,6 +34,7 @@
34
34
  "http-status": "^1.7.4",
35
35
  "jsonwebtoken": "^9.0.0",
36
36
  "moment": "^2.30.1",
37
+ "moment-timezone": "^0.6.0",
37
38
  "qs": "^6.13.0",
38
39
  "swagger-autogen": "^2.23.7",
39
40
  "swagger-ui-express": "^5.0.0",