-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.js
63 lines (58 loc) · 1.55 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
52
53
54
55
56
57
58
59
60
61
62
63
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: [],
allowedAtributes: {},
});
if (clean !== value)
return helpers.error('string.escapeHTML', { value });
return clean;
},
},
},
});
const Joi = BaseJoi.extend(extension);
module.exports.memberSchema = Joi.object({
member: Joi.object({
project: Joi.string().required().escapeHTML(),
// logo: Joi.alternatives()
// .try(
// Joi.string()
// .uri({ scheme: ['http', 'https'] })
// .escapeHTML(),
// Joi.binary()
// .encoding('base64')
// .strict()
// .label('Image file')
// .custom((value, helpers) => {
// const validFormats = ['jpg', 'jpeg', 'png'];
// const fileFormat = helpers.originalName
// .split('.')
// .pop()
// .toLowerCase();
// if (!validFormats.includes(fileFormat)) {
// return helpers.error(
// 'Logo file format must be one of ' + validFormats.join(', ')
// );
// }
// return value;
// }, 'Logo format validation')
// .max(5 * 1024 * 1024)
// )
url: Joi.string()
.uri({ scheme: ['http', 'https'] })
.escapeHTML()
.required(),
description: Joi.string().max(280).trim().escapeHTML().required(),
status: Joi.string().escapeHTML().required(),
}).required(),
});