User schema

pull/1/head
sundowndev 2018-11-14 18:14:57 +01:00
parent 145389a619
commit e889d37333
1 changed files with 25 additions and 0 deletions

25
app/schemas/user.js Normal file
View File

@ -0,0 +1,25 @@
const Joi = require('joi');
module.exports = (req, res, next) => {
const schema = Joi.object().keys({
firstname: Joi.string().min(2).required(),
lastname: Joi.string().min(2).required(),
username: Joi.string().alphanum().min(3).max(30)
.required(),
password: Joi.string().required(),
});
Joi.validate({
firstname: req.body.firstname,
lastname: req.body.lastname,
username: req.body.username,
password: req.body.password,
},
schema, (validateErr) => {
if (validateErr) {
return next({ status: 400, message: 'Form is invalid.', error: validateErr });
}
return next();
});
};