Now isValid for schema validation, prints the message when debug is on;

Added dependency of debug
This commit is contained in:
alexandercerutti
2018-08-27 14:00:36 +02:00
parent 788245b140
commit b8e6eec016
3 changed files with 47 additions and 6 deletions

46
package-lock.json generated
View File

@@ -199,6 +199,16 @@
"qs": "6.5.1", "qs": "6.5.1",
"raw-body": "2.3.2", "raw-body": "2.3.2",
"type-is": "~1.6.15" "type-is": "~1.6.15"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"brace-expansion": { "brace-expansion": {
@@ -396,9 +406,9 @@
} }
}, },
"debug": { "debug": {
"version": "2.6.9", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": { "requires": {
"ms": "2.0.0" "ms": "2.0.0"
} }
@@ -637,6 +647,16 @@
"type-is": "~1.6.16", "type-is": "~1.6.16",
"utils-merge": "1.0.1", "utils-merge": "1.0.1",
"vary": "~1.1.2" "vary": "~1.1.2"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"external-editor": { "external-editor": {
@@ -699,6 +719,16 @@
"parseurl": "~1.3.2", "parseurl": "~1.3.2",
"statuses": "~1.4.0", "statuses": "~1.4.0",
"unpipe": "~1.0.0" "unpipe": "~1.0.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"flat-cache": { "flat-cache": {
@@ -1382,6 +1412,16 @@
"on-finished": "~2.3.0", "on-finished": "~2.3.0",
"range-parser": "~1.2.0", "range-parser": "~1.2.0",
"statuses": "~1.4.0" "statuses": "~1.4.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"serve-static": { "serve-static": {

View File

@@ -10,6 +10,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"archiver": "^2.1.1", "archiver": "^2.1.1",
"debug": "^3.1.0",
"express": "^4.16.3", "express": "^4.16.3",
"joi": "^13.6.0", "joi": "^13.6.0",
"moment": "^2.22.2", "moment": "^2.22.2",

View File

@@ -66,11 +66,11 @@ module.exports = {
locationsDict, locationsDict,
transitType transitType
}, },
isValid: (opts, schemaName, debug = false) => { isValid: (opts, schemaName) => {
let validation = Joi.validate(opts, schemaName); let validation = Joi.validate(opts, schemaName);
if (debug) { if (validation.error) {
console.log(validation) debug(`validation failed due to :: ${validation.error.message}`);
} }
return !validation.error; return !validation.error;