-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.js
51 lines (44 loc) · 1.43 KB
/
schemas.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
42
43
44
45
46
47
48
49
50
51
// server-side validation
const basejoi = require('joi');
const sanitizeHtml = require('sanitize-html');
const extension = (joi) => ({
type: 'string',
base: joi.string(),
messages: {
'string.escapeHTML': '{{#label}} must not include HTML!'
},
rules: {
escapeHTML: {
validate(value, helpers) {
const clean = sanitizeHtml(value, {
allowedTags: [],
allowedAttributes: {},
});
if (clean !== value) return helpers.error('string.escapeHTML', { value })
return clean;
}
}
}
});
const joi = basejoi.extend(extension)
module.exports.shopSchema = joi.object({ // validateShop only validate req.body not req.files
shop: joi.object({
name: joi.string().required().escapeHTML(),
category:joi.string().required().escapeHTML(),
location:joi.string().required().escapeHTML(),
description:joi.string().required().escapeHTML()
// image:joi.string().required()
}).required(),
deleteImages: joi.array()
});
module.exports.reviewSchema = joi.object({
review: joi.object({
rating:joi.number().required().min(0).max(5),
body:joi.string().required().escapeHTML()
}).required()
});
module.exports.categorySchema = joi.object({
category: joi.object({
name: joi.string().required().escapeHTML()
}).required()
});