forked from shannon-jx/ForACauseFinal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.js
44 lines (40 loc) · 1.36 KB
/
schema.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
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.opportunitySchema = Joi.object({
opportunity: Joi.object({
title: Joi.string().required().escapeHTML(),
location: Joi.string().required().escapeHTML(),
description: Joi.string().required().escapeHTML(),
email: Joi.string().required().escapeHTML(),
contact: Joi.string().required().escapeHTML()
// website: Joi.string().required()
// image: Joi.string().required()
}).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()
});