-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoiSchema.js
42 lines (36 loc) · 1.22 KB
/
joiSchema.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
const { string } = require('joi');
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);
//VALIDATE JOI SCHEMA FOR DB
module.exports.campgroundJoiSchema = Joi.object({
title: Joi.string().required().escapeHTML(),
location: Joi.string().required().escapeHTML(),
price: Joi.number().required().min(1),
//image: Joi.string().required(),
description: Joi.string().required().escapeHTML(),
deleteImages: Joi.array()
}).required();
module.exports.reviewJoiSchema = Joi.object({
reviewText: Joi.string().required().escapeHTML(),
rating: Joi.number().required()
}).required();
//module.exports = campgroundJoiSchema;