anote-server-libs 0.4.3 → 0.4.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/package.json +1 -1
- package/services/WithBody.js +1 -11
- package/services/WithBody.ts +1 -10
package/package.json
CHANGED
package/services/WithBody.js
CHANGED
|
@@ -28,21 +28,11 @@ function WithBody(schema) {
|
|
|
28
28
|
});
|
|
29
29
|
schema.required = required;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
const validate = ajv.compile(schema);
|
|
32
32
|
return function (_, __, descriptor) {
|
|
33
33
|
if (typeof descriptor.value === 'function') {
|
|
34
34
|
const previousMethod = descriptor.value;
|
|
35
35
|
descriptor.value = function (req, res) {
|
|
36
|
-
const keys = Object.getOwnPropertyNames(schema.properties);
|
|
37
|
-
let dynKey = false;
|
|
38
|
-
keys.forEach(key => {
|
|
39
|
-
if (typeof schema.properties[key] === 'string') {
|
|
40
|
-
schema.properties[key] = this.config.app.endpointsSchemas[schema.properties[key]];
|
|
41
|
-
dynKey = true;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
if (dynKey)
|
|
45
|
-
validate = ajv.compile(schema);
|
|
46
36
|
if (req.method.toUpperCase() !== 'POST' && req.method.toUpperCase() !== 'PUT') {
|
|
47
37
|
return previousMethod.call(this, req, res);
|
|
48
38
|
}
|
package/services/WithBody.ts
CHANGED
|
@@ -28,20 +28,11 @@ export function WithBody(schema: any) {
|
|
|
28
28
|
});
|
|
29
29
|
schema.required = required;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
const validate = ajv.compile(schema);
|
|
32
32
|
return function(_: any, __: string, descriptor: PropertyDescriptor) {
|
|
33
33
|
if(typeof descriptor.value === 'function') {
|
|
34
34
|
const previousMethod = descriptor.value;
|
|
35
35
|
descriptor.value = function(this: any, req: Request, res: Response) {
|
|
36
|
-
const keys = Object.getOwnPropertyNames(schema.properties);
|
|
37
|
-
let dynKey = false;
|
|
38
|
-
keys.forEach(key => {
|
|
39
|
-
if(typeof schema.properties[key] === 'string') {
|
|
40
|
-
schema.properties[key] = this.config.app.endpointsSchemas[schema.properties[key]];
|
|
41
|
-
dynKey = true;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
if(dynKey) validate = ajv.compile(schema);
|
|
45
36
|
if(req.method.toUpperCase() !== 'POST' && req.method.toUpperCase() !== 'PUT') {
|
|
46
37
|
return previousMethod.call(this, req, res);
|
|
47
38
|
}
|