2018-03-23 14:35:29 +00:00
|
|
|
const Joi = require('joi');
|
|
|
|
Joi.objectId = require('joi-objectid')(Joi);
|
|
|
|
|
|
|
|
const schema = Joi.object().keys({
|
|
|
|
block: Joi.string(),
|
|
|
|
blockId: Joi.objectId(),
|
2018-10-23 16:21:53 +03:00
|
|
|
challengeOrder: Joi.number(),
|
2018-07-10 17:21:07 +03:00
|
|
|
challengeType: Joi.number()
|
|
|
|
.min(0)
|
|
|
|
.max(9)
|
|
|
|
.required(),
|
2018-03-23 14:35:29 +00:00
|
|
|
checksum: Joi.number(),
|
|
|
|
dashedName: Joi.string(),
|
2018-10-23 16:21:53 +03:00
|
|
|
description: Joi.string().required(),
|
2018-03-23 14:35:29 +00:00
|
|
|
fileName: Joi.string(),
|
2018-10-23 16:21:53 +03:00
|
|
|
files: Joi.array().items(
|
2018-03-23 14:35:29 +00:00
|
|
|
Joi.object().keys({
|
|
|
|
key: Joi.string(),
|
|
|
|
ext: Joi.string(),
|
|
|
|
name: Joi.string(),
|
2018-07-10 17:21:07 +03:00
|
|
|
head: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
|
|
|
|
tail: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
|
2018-05-22 13:43:14 +01:00
|
|
|
contents: [
|
|
|
|
Joi.array().items(Joi.string().allow('')),
|
|
|
|
Joi.string().allow('')
|
|
|
|
]
|
2018-03-23 14:35:29 +00:00
|
|
|
})
|
|
|
|
),
|
|
|
|
guideUrl: Joi.string().uri({ scheme: 'https' }),
|
2018-09-25 11:12:03 -04:00
|
|
|
videoUrl: Joi.string().allow(''),
|
2018-03-23 14:35:29 +00:00
|
|
|
helpRoom: Joi.string(),
|
|
|
|
id: Joi.objectId().required(),
|
2018-10-23 16:21:53 +03:00
|
|
|
instructions: Joi.string().required(),
|
2018-03-23 14:35:29 +00:00
|
|
|
isBeta: Joi.bool(),
|
|
|
|
isComingSoon: Joi.bool(),
|
|
|
|
isLocked: Joi.bool(),
|
|
|
|
isPrivate: Joi.bool(),
|
|
|
|
isRequired: Joi.bool(),
|
|
|
|
name: Joi.string(),
|
|
|
|
order: Joi.number(),
|
|
|
|
required: Joi.array().items(
|
|
|
|
Joi.object().keys({
|
|
|
|
link: Joi.string(),
|
|
|
|
raw: Joi.bool(),
|
|
|
|
src: Joi.string(),
|
|
|
|
crossDomain: Joi.bool()
|
|
|
|
})
|
|
|
|
),
|
2018-07-10 17:21:07 +03:00
|
|
|
solutions: Joi.array().items(Joi.string().optional()),
|
2018-03-23 14:35:29 +00:00
|
|
|
superBlock: Joi.string(),
|
|
|
|
superOrder: Joi.number(),
|
|
|
|
suborder: Joi.number(),
|
|
|
|
tests: Joi.array().items(
|
2018-05-22 13:43:14 +01:00
|
|
|
// public challenges
|
2018-03-23 14:35:29 +00:00
|
|
|
Joi.object().keys({
|
|
|
|
text: Joi.string().required(),
|
2018-07-10 17:21:07 +03:00
|
|
|
testString: Joi.string()
|
|
|
|
.allow('')
|
|
|
|
.required()
|
2018-05-22 13:43:14 +01:00
|
|
|
}),
|
|
|
|
// our tests used in certification verification
|
|
|
|
Joi.object().keys({
|
|
|
|
id: Joi.string().required(),
|
|
|
|
title: Joi.string().required()
|
2018-03-23 14:35:29 +00:00
|
|
|
})
|
|
|
|
),
|
|
|
|
template: Joi.string(),
|
|
|
|
time: Joi.string().allow(''),
|
2018-09-20 22:24:45 +09:00
|
|
|
title: Joi.string().required()
|
2018-03-23 14:35:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
exports.validateChallenge = function validateChallenge(challenge) {
|
|
|
|
return Joi.validate(challenge, schema);
|
|
|
|
};
|