validate(cube, errorReporter) { Joi.validate(cube, cubeSchema, (err) => { if (err) { errorReporter.error(err.message); } else { this.validCubes[cube.name] = true; } }); }
validateAndCompile(dashboardTemplate, errorReporter) { Joi.validate(dashboardTemplate, dashboardTemplateSchema, (err) => { if (err) { errorReporter.error(err.message); } else { this.compiledTemplates.push(this.compileTemplate(dashboardTemplate, errorReporter)); } }); }
Joi.object().keys({ title: Joi.string(), description: Joi.string(), measures: Joi.func(), dimensions: Joi.func(), segments: Joi.func(), order: Joi.array().items(Joi.object().keys({ member: Joi.func().required(), direction: Joi.any().valid('asc', 'desc').required() })), filters: Joi.array().items(Joi.object().keys({ member: Joi.func().required(), operator: Joi.any().valid('contains', 'notContains', 'equals', 'set', 'notSet', 'gt', 'gte', 'lt', 'lte'), params: Joi.array().items(Joi.string().allow('').optional()) })), timeDimension: Joi.object().keys({ dimension: Joi.func().required(), dateRange: Joi.string().required(), granularity: Joi.any().valid('hour', 'day', 'week', 'month', 'year', null) }), visualization: Joi.object().keys({ type: Joi.any().valid('bar', 'line', 'table', 'area', 'singleValue', 'pie').required(), autoScale: Joi.boolean(), showTotal: Joi.boolean(), y2Axis: Joi.boolean(), showLegend: Joi.boolean(), axisRotated: Joi.boolean(), showYLabel: Joi.boolean(), showY2Label: Joi.boolean(), showTrendline: Joi.boolean(),
const normalizeQuery = (query) => { const { error } = Joi.validate(query, querySchema); if (error) { throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
/** * Get the component configuration schema. * Can be overriden by the component implementation class * @returns {*} */ getConfigurationSchema() { return this.joi.object(); }
router.delete('/:id', async (req, res, next) => { try { await schema.validateAsync(req.body).catch(reason => { throw new ErrorHandler(422, reason); }); const id = req.params.id; await userService.delete([id]); return res.status(204).send(); } catch (e) { next(e); } });
_.curry((schema, payload) => { const { error, value } = Joi.validate(payload, schema, joiOptions); return { errors: parseJoiErrors(error), value, }; })
router.post('/', async (req, res, next) => { try { await schema.validateAsync(req.body).catch(reason => { throw new ErrorHandler(422, reason); }); const first_name = req.body.first_name; const last_name = req.body.last_name; await userService.post([first_name, last_name]); return res.status(200).send(); } catch (e) { next(e); } });
lab.before(async () => { DummyModel = class extends MongoModels {}; DummyModel.schema = Joi.object().keys({ _id: Joi.object(), count: Joi.number(), group: Joi.string(), isCool: Joi.boolean(), name: Joi.string().required() }); DummyModel.collectionName = 'dummies'; await MongoModels.connect(config.connection, config.options); });