@bee.js/node 0.0.51 → 0.0.52
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/beeRequest.js +46 -43
- package/beehive.js +491 -491
- package/index.js +14 -14
- package/lib/DBA/beeDBA.js +133 -133
- package/lib/DEV/beeDEV.js +41 -41
- package/lib/JWT/beeJWT.js +71 -71
- package/lib/ORM/beeORM.js +364 -364
- package/lib/WEB/freeRoute.js +4 -4
- package/lib/WEB/route.js +27 -27
- package/lib/beeHive/create.js +51 -51
- package/lib/beeHive/headers.js +9 -9
- package/lib/beeHive/load.js +19 -19
- package/lib/beeHive/log.js +2 -2
- package/lib/beeHive/routes.js +34 -34
- package/lib/beeHive/start.js +29 -29
- package/package.json +40 -40
- package/security/index.js +8 -8
- package/services/CRON.js +8 -8
- package/services/EMAIL.js +2 -2
- package/services/HTTP.js +32 -32
- package/services/HTTPS.js +31 -31
- package/services/LOGS.js +7 -7
- package/services/SCRIPT.js +13 -13
- package/services/SHELL.js +2 -2
- package/services/index.js +9 -9
- package/tools/beeTools.js +18 -18
- package/tools/guid.js +15 -15
- package/tools/hash.js +6 -6
- package/tools/model.js +20 -20
- package/tools/slug.js +16 -16
- package/tools/string.js +55 -55
package/beeRequest.js
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
module.exports = function request(req, res, ...validations) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.status(errorCode)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
module.exports = async function request(req, res, ...validations) {
|
|
2
|
+
const failConditions = [];
|
|
3
|
+
const error = {};
|
|
4
|
+
let valid = true;
|
|
5
|
+
|
|
6
|
+
req.onlyFields = {};
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < validations.length; i++) {
|
|
9
|
+
const validation = validations[i];
|
|
10
|
+
|
|
11
|
+
// filter fields
|
|
12
|
+
if (validation.onlyFields && validation.onlyFields !== "*")
|
|
13
|
+
req.onlyFields[validation.model] = validation.onlyFields
|
|
14
|
+
.split(",")
|
|
15
|
+
.map((field) => field.trim()); //TODO otimizar colocando na memoria
|
|
16
|
+
|
|
17
|
+
// fail conditions
|
|
18
|
+
for ([condition, fn] of Object.entries(validation.failConditions || [])) {
|
|
19
|
+
let fail = await fn(req);
|
|
20
|
+
|
|
21
|
+
if (!fail || fail.error === true) {
|
|
22
|
+
failConditions.push(condition);
|
|
23
|
+
error.message = fail && fail.message ? fail.message : "";
|
|
24
|
+
valid = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new Promise(function (resolve, reject) {
|
|
30
|
+
valid === true
|
|
31
|
+
? resolve(req)
|
|
32
|
+
: reject({
|
|
33
|
+
requestError: function (_error = error, errorCode = 400) {
|
|
34
|
+
try {
|
|
35
|
+
res.status(errorCode).send({
|
|
36
|
+
error: {
|
|
37
|
+
message:
|
|
38
|
+
_error.message || "There was an error in the request",
|
|
39
|
+
},
|
|
40
|
+
failConditions,
|
|
41
|
+
});
|
|
42
|
+
} catch {}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|