Skip to content

Instantly share code, notes, and snippets.

@myndzi
Last active May 18, 2017 00:38
Show Gist options
  • Save myndzi/22252bbb83afb9fce9148523d7599a89 to your computer and use it in GitHub Desktop.
Save myndzi/22252bbb83afb9fce9148523d7599a89 to your computer and use it in GitHub Desktop.
const schema = Joi.object().keys({
isRegister: Joi.any(),
username: Joi.string(),
password: Joi.string(),
email: Joi.string()
}).with('isRegister', 'username', 'password');
app.post('/register', function (req, res) {
const isValid = schema.validate(Object.assign({ isRegister: true }, req.params));
});
app.post('/update_user', function (req, res) {
const isValid = schema.validate(req.params);
});
const schema = Joi.object().keys({
username: Joi.string(),
password: Joi.string(),
email: Joi.string()
});
app.post('/register', function (req, res) {
const isValid = schema.requiredKeys('username', 'password').validate(req.params);
});
app.post('/update_user', function (req, res) {
const isValid = schema.validate(req.params);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment