We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We currently have support for validations as objects in validations. These can be used in the request cycle with $.validate.
validations
$.validate
How do we use them in scripts, outside the request cycle?
$.validate currently throws (halt), we just want to get the errors. If I want to validate some data:
var { validate } = require('waveorb') var values = { name: 'Baner', email: 'e@xample.com' } var validator = await validate(app.validations.userCreate, { values }) if (validator.errors) { // handle errors } else { // No errors, empty object }
This cannot use waveorb-validations at the moment, since it depends on $.
waveorb-validations
$
If we are actually saving data after this, it feels more natural to use a classic ORM maybe:
var { validate } = require('waveorb') class Project { constructor (values) { this.values = values } valid() { var validator = await validate(app.validations.userCreate, { values: this.values }) return !!validator.errors } }
We could also introduce a validator function which handles the setup:
validator
var { validate } = require('waveorb') module.exports = function userCreateValidator($, validation, data) { if (!$.db && typeof global.db != 'undefined') $.db = global.db if (!$.params) $.params = {} // ... Add missing stuff for waveorb-validator and '$' return validate($, data)(validation) }
The text was updated successfully, but these errors were encountered:
Added a validator function to app.validator
app.validator
Sorry, something went wrong.
No branches or pull requests
We currently have support for validations as objects in
validations
. These can be used in the request cycle with$.validate
.How do we use them in scripts, outside the request cycle?
$.validate
currently throws (halt), we just want to get the errors. If I want to validate some data:This cannot use
waveorb-validations
at the moment, since it depends on$
.If we are actually saving data after this, it feels more natural to use a classic ORM maybe:
We could also introduce a
validator
function which handles the setup:The text was updated successfully, but these errors were encountered: