This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.js
55 lines (50 loc) · 1.56 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
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.solutionSchema = Joi.object({
AnswerStone: Joi.string().required().escapeHTML(),
});
module.exports.stoneSchema = Joi.object({
stone: Joi.object({
name: Joi.string().required().escapeHTML(),
title: Joi.string().required().escapeHTML(),
text: Joi.string().required().escapeHTML(),
body: Joi.string().required().escapeHTML(),
imageURL: Joi.string().uri().required().escapeHTML(),
filelink: Joi.string().uri().optional().allow('').escapeHTML(),
hint: Joi.string().required().escapeHTML(),
solution: Joi.string().required().escapeHTML(),
}),
});
module.exports.userSchema = Joi.object({
username: Joi.string().required().escapeHTML(),
password: Joi.string().required().escapeHTML(),
team_member_1: {
name: Joi.string().required().escapeHTML(),
roll_no: Joi.string().required().escapeHTML(),
},
team_member_2: {
name: Joi.string().optional().allow('').escapeHTML(),
roll_no: Joi.string().optional().allow('').escapeHTML(),
},
});