-
Notifications
You must be signed in to change notification settings - Fork 0
/
validatorSchemas.js
46 lines (37 loc) · 1.12 KB
/
validatorSchemas.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
const Joi = require('joi')
const htmlSanitizer = require('sanitize-html')
const extension = (joi) => ({
type: 'string',
base: joi.string(),
message: {
'string.escapeHTML': '{{#label}} must not include HTML'
},
rules: {
escapeHTML: {
validate(value, helpers) {
const clean = htmlSanitizer(value, {
allowedTags: [],
allowedAtributes: {},
})
if (clean !== value) return helpers.error('string.escapeHTML', { value })
return clean
}
}
}
})
module.exports.campgroundSchema = Joi.object({
campground: Joi.object({
title: Joi.string().required(),
price: Joi.number().required().min(0),
// img: Joi.string().required(),
description: Joi.string().required(),
location: Joi.string().required()
}).required(),
deleteImgs: Joi.array()
})
module.exports.reviewSchema = Joi.object({
review: Joi.object({
body: Joi.string().required(),
rating: Joi.number().required().min(0).max(5)
}).required()
})