diff --git a/curriculum/schema/challengeSchema.js b/curriculum/schema/challengeSchema.js index 2bcc621dab..adc6a99f45 100644 --- a/curriculum/schema/challengeSchema.js +++ b/curriculum/schema/challengeSchema.js @@ -1,7 +1,11 @@ const Joi = require('joi'); Joi.objectId = require('joi-objectid')(Joi); +const path = require('path'); +require('dotenv').config({ path: path.resolve(__dirname, '../../.env') }); -const schema = Joi.object().keys({ +const { LOCALE: lang = 'english' } = process.env; + +let schema = Joi.object().keys({ block: Joi.string(), blockId: Joi.objectId(), challengeOrder: Joi.number(), @@ -69,6 +73,12 @@ const schema = Joi.object().keys({ title: Joi.string().required() }); +if (lang !== 'english') { + schema = schema.append({ + localeTitle: Joi.string().required() + }); +} + exports.validateChallenge = function validateChallenge(challenge) { return Joi.validate(challenge, schema); };