-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.js
31 lines (26 loc) · 923 Bytes
/
validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Validation
const Joi = require('@hapi/joi');
function validateRegister(data) {
const schema = Joi.object({
name: Joi.string().min(2).required(),
email: Joi.string().min(6).email().required(),
password: Joi.string().min(6).required()
});
return schema.validate(data).error;
}
function validateLogin(data) {
const schema = Joi.object({
email: Joi.string().min(6).email().required(),
password: Joi.string().min(6).required()
});
return schema.validate(data).error;
}
function validateDbSet(data) {
const schema = Joi.object({
todos: (data.field === 0 || data.field === null || data.field !== 1) ? (Joi.array().required()):(Joi.array()),
prevTasks: (data.field === 1 || data.field === null || data.field !== 0) ? (Joi.array().required()):(Joi.array()),
field: Joi.number().allow(null)
});
return schema.validate(data).error;
}
module.exports = {validateLogin, validateRegister, validateDbSet};