c2-http 1.0.105 → 1.0.107
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/middleware/global-middleware/item/MiddlewareBody.d.ts +1 -1
- package/dist/middleware/global-middleware/item/MiddlewareBody.js +31 -10
- package/dist/model/Controller.js +1 -1
- package/dist/model/CrudController.js +7 -6
- package/dist/model/IControllerOptions.d.ts +1 -1
- package/package.json +1 -1
|
@@ -13,22 +13,43 @@ class MiddlewareBody {
|
|
|
13
13
|
expressApplication.use(body_parser_1.default.text({ limit: "5mb" }));
|
|
14
14
|
expressApplication.use((request, response, next) => {
|
|
15
15
|
if (request.body && typeof request.body === "object") {
|
|
16
|
-
this.convertDates(request);
|
|
16
|
+
this.convertDates(request.body, request.headers);
|
|
17
17
|
}
|
|
18
18
|
next();
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
convertDates(request) {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
// private convertDates(request: Request): void {
|
|
22
|
+
// for (const key in request.body) {
|
|
23
|
+
// if (request.body.hasOwnProperty(key)) {
|
|
24
|
+
// if (key.endsWith("Date") || key.endsWith("DateTime")) {
|
|
25
|
+
// const tz = request.headers["timezone"] as string || "America/Sao_Paulo" as string; // fallback padrão
|
|
26
|
+
// // interpreta como GMT-3
|
|
27
|
+
// request.body[key] = moment.tz(request.body[key], "YYYY-MM-DD", tz);
|
|
28
|
+
// // obj[key] = moment.utc(obj[key]);
|
|
29
|
+
// } else if (typeof request.body[key] === "object" && request.body[key] !== null) {
|
|
30
|
+
// this.convertDates(request.body[key]);
|
|
31
|
+
// }
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
convertDates(obj, headers) {
|
|
36
|
+
if (Array.isArray(obj)) {
|
|
37
|
+
// percorre arrays também
|
|
38
|
+
for (let i = 0; i < obj.length; i++) {
|
|
39
|
+
this.convertDates(obj[i], headers);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (typeof obj === "object" && obj !== null) {
|
|
43
|
+
for (const key in obj) {
|
|
44
|
+
if (!obj.hasOwnProperty(key))
|
|
45
|
+
continue;
|
|
46
|
+
const value = obj[key];
|
|
24
47
|
if (key.endsWith("Date") || key.endsWith("DateTime")) {
|
|
25
|
-
const tz =
|
|
26
|
-
|
|
27
|
-
request.body[key] = moment_timezone_1.default.tz(request.body[key], "YYYY-MM-DD", tz);
|
|
28
|
-
// obj[key] = moment.utc(obj[key]);
|
|
48
|
+
const tz = headers["timezone"] || "America/Sao_Paulo"; // fallback padrão
|
|
49
|
+
obj[key] = moment_timezone_1.default.tz(value, "YYYY-MM-DD", tz).utc();
|
|
29
50
|
}
|
|
30
|
-
else
|
|
31
|
-
this.convertDates(
|
|
51
|
+
else {
|
|
52
|
+
this.convertDates(value, headers); // recursivo
|
|
32
53
|
}
|
|
33
54
|
}
|
|
34
55
|
}
|
package/dist/model/Controller.js
CHANGED
|
@@ -23,7 +23,7 @@ class Controller {
|
|
|
23
23
|
if (defaultPrefixRole.startsWith("/")) {
|
|
24
24
|
defaultPrefixRole = defaultPrefixRole.replace("/", "");
|
|
25
25
|
}
|
|
26
|
-
this.options.prefixRole = defaultPrefixRole.replaceAll("/", "-");
|
|
26
|
+
this.options.prefixRole = [defaultPrefixRole.replaceAll("/", "-")];
|
|
27
27
|
}
|
|
28
28
|
this.options.uri = `${this.options.basePath}${this.options.relativePath}`;
|
|
29
29
|
}
|
|
@@ -62,42 +62,43 @@ class CrudController extends Controller_1.Controller {
|
|
|
62
62
|
router: this.routers,
|
|
63
63
|
method: "get",
|
|
64
64
|
uri: `${this.options.uri}/:id`,
|
|
65
|
-
|
|
65
|
+
// MiddlewareCheckRolesFlow.middleware(this.options.prefixRole.map((pr: string) => `${pr}:read`)),
|
|
66
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:read`), options.middlewareCheckAuthorization),
|
|
66
67
|
controllerFn: this.getByIdRunner
|
|
67
68
|
}));
|
|
68
69
|
this.routesControlled.push(new ControllerRoute_1.ControllerRoute({
|
|
69
70
|
router: this.routers,
|
|
70
71
|
method: "get",
|
|
71
72
|
uri: `${this.options.uri}`,
|
|
72
|
-
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(
|
|
73
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:read`), options.middlewareCheckAuthorization),
|
|
73
74
|
controllerFn: this.searchRunner
|
|
74
75
|
}));
|
|
75
76
|
this.routesControlled.push(new ControllerRoute_1.ControllerRoute({
|
|
76
77
|
router: this.routers,
|
|
77
78
|
method: "patch",
|
|
78
79
|
uri: `${this.options.uri}`,
|
|
79
|
-
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(
|
|
80
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:read`), options.middlewareCheckAuthorization),
|
|
80
81
|
controllerFn: this.deepSearchRunner
|
|
81
82
|
}));
|
|
82
83
|
this.routesControlled.push(new ControllerRoute_1.ControllerRoute({
|
|
83
84
|
router: this.routers,
|
|
84
85
|
method: "post",
|
|
85
86
|
uri: `${this.options.uri}`,
|
|
86
|
-
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(
|
|
87
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:create`), options.middlewareCheckAuthorization),
|
|
87
88
|
controllerFn: this.createRunner
|
|
88
89
|
}));
|
|
89
90
|
this.routesControlled.push(new ControllerRoute_1.ControllerRoute({
|
|
90
91
|
router: this.routers,
|
|
91
92
|
method: "patch",
|
|
92
93
|
uri: `${this.options.uri}/:id`,
|
|
93
|
-
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(
|
|
94
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:edit`), options.middlewareCheckAuthorization),
|
|
94
95
|
controllerFn: this.updateRunner
|
|
95
96
|
}));
|
|
96
97
|
this.routesControlled.push(new ControllerRoute_1.ControllerRoute({
|
|
97
98
|
router: this.routers,
|
|
98
99
|
method: "delete",
|
|
99
100
|
uri: `${this.options.uri}/:id`,
|
|
100
|
-
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(
|
|
101
|
+
middlewareCheckAuthorization: new ControllerRoleMiddleware_1.ControllerRoleMiddleware(this.options.prefixRole.map((pr) => `${pr}:delete`), options.middlewareCheckAuthorization),
|
|
101
102
|
controllerFn: this.deleteRunner
|
|
102
103
|
}));
|
|
103
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.107",
|
|
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>",
|