badmfck-api-server 1.6.6 → 1.6.8
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.
@@ -47,7 +47,7 @@ async function Initializer(services) {
|
|
47
47
|
exports.Initializer = Initializer;
|
48
48
|
class APIService extends BaseService_1.BaseService {
|
49
49
|
static nextLogID = 0;
|
50
|
-
version = "1.6.
|
50
|
+
version = "1.6.8";
|
51
51
|
options;
|
52
52
|
monitor;
|
53
53
|
monitorIndexFile;
|
@@ -140,9 +140,13 @@ class APIService extends BaseService_1.BaseService {
|
|
140
140
|
params: req.params
|
141
141
|
};
|
142
142
|
}
|
143
|
-
if (this.options.onNetworkLog && log)
|
144
|
-
this.options.onNetworkLog(log);
|
145
143
|
const execute = async () => {
|
144
|
+
const body = req.body;
|
145
|
+
if (req.query && typeof req.query === "object") {
|
146
|
+
for (let i in req.query) {
|
147
|
+
body[i] = req.query[i];
|
148
|
+
}
|
149
|
+
}
|
146
150
|
const httpRequest = {
|
147
151
|
raw: req,
|
148
152
|
method: req.method,
|
@@ -150,7 +154,6 @@ class APIService extends BaseService_1.BaseService {
|
|
150
154
|
params: req.params,
|
151
155
|
headers: req.headers,
|
152
156
|
endpoint: ep,
|
153
|
-
query: req.query
|
154
157
|
};
|
155
158
|
let result;
|
156
159
|
try {
|
@@ -14,5 +14,6 @@ export declare enum ValidationReport {
|
|
14
14
|
}
|
15
15
|
export declare class Validator {
|
16
16
|
static validateObject(fields: string[], object: any): boolean;
|
17
|
+
static convertToType<T>(value: any, type: "string" | "number" | "boolean" | "date"): T | null;
|
17
18
|
static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
|
18
19
|
}
|
@@ -20,6 +20,43 @@ class Validator {
|
|
20
20
|
}
|
21
21
|
return true;
|
22
22
|
}
|
23
|
+
static convertToType(value, type) {
|
24
|
+
if (value === null || value === undefined)
|
25
|
+
return null;
|
26
|
+
if (type === "string") {
|
27
|
+
if (typeof value === "object") {
|
28
|
+
let result = null;
|
29
|
+
try {
|
30
|
+
result = JSON.stringify(value);
|
31
|
+
}
|
32
|
+
catch (e) { }
|
33
|
+
if (result !== null)
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
return value + "";
|
37
|
+
}
|
38
|
+
if (type === "boolean") {
|
39
|
+
if (typeof value === "boolean")
|
40
|
+
return value;
|
41
|
+
if (typeof value === "number")
|
42
|
+
return value > 0;
|
43
|
+
if (typeof value === "object")
|
44
|
+
return false;
|
45
|
+
if (typeof value === "string")
|
46
|
+
return (value.toLowerCase() === "true");
|
47
|
+
}
|
48
|
+
if (type === "date") {
|
49
|
+
if (typeof value === "string" || typeof value === "number")
|
50
|
+
return new Date(value);
|
51
|
+
return null;
|
52
|
+
}
|
53
|
+
if (typeof value === "number")
|
54
|
+
return value;
|
55
|
+
if (typeof value === "object")
|
56
|
+
return 0;
|
57
|
+
const num = parseInt(value + "");
|
58
|
+
return num;
|
59
|
+
}
|
23
60
|
static validateValue(value, opt) {
|
24
61
|
if (value === undefined || value === null)
|
25
62
|
return ValidationReport.VALUE_IS_NULL;
|