-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.js
41 lines (34 loc) · 1.1 KB
/
validation.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
32
33
34
35
36
37
38
39
40
41
// Validation
const Joi = require("@hapi/joi");
const registerValidation = (data) => {
const schema = Joi.object({
first_name: Joi.string().min(2).required(),
last_name: Joi.string().min(2).required(),
username: Joi.string().min(3).required(),
email: Joi.string().required().email(),
password: Joi.string().required().min(8),
});
return schema.validate(data);
};
const loginValidation = (data) => {
const schema = Joi.object({
email: Joi.string().required().email(),
password: Joi.string().required(),
});
return schema.validate(data);
};
const newAuctionValidation = (data) => {
const schema = Joi.object({
created_by: Joi.string().required(),
item_name: Joi.string().required(),
item_description: Joi.string().required(),
date_ends: Joi.string().required(),
initial_price: Joi.string().required(),
pictures: Joi.array(),
category: Joi.string(),
});
return schema.validate(data);
};
module.exports.registerValidation = registerValidation;
module.exports.loginValidation = loginValidation;
module.exports.newAuctionValidation = newAuctionValidation;