-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.js
More file actions
44 lines (39 loc) · 1.25 KB
/
Copy pathschemas.js
File metadata and controls
44 lines (39 loc) · 1.25 KB
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
const BaseJoi = require('joi');
const mongoose = require('mongoose');
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.CampgroundSchema = joi.object({
campground:joi.object({
title:joi.string().required().escapeHTML(),
price:joi.number().min(0).required(),
// image:joi.string().required(),
location:joi.string().required().escapeHTML(),
description:joi.string().required().escapeHTML()
}).required(),
deleteImages:joi.array()
});
module.exports.ReviewSchema = joi.object({
Review:joi.object({
rating:joi.number().required().min(1).max(5),
body:joi.string().required().escapeHTML()
}).required()
});