Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Joi from 'joi';
import objectId from 'joi-objectid';
import entities from './entities';
import templates from '../templates/templates';
import thesauris from '../thesauris/thesauris';
import needsAuthorization from '../auth/authMiddleware';
import { validation } from '../utils';
import { saveSchema, metadataSchema, iconSchema } from './endpointSchema';
Joi.objectId = objectId(Joi);
export default (app) => {
app.post(
'/api/entities',
needsAuthorization(['admin', 'editor']),
validation.validateRequest(saveSchema),
(req, res, next) => entities.save(req.body, { user: req.user, language: req.language })
.then((response) => {
res.json(response);
return templates.getById(response.template);
})
.then(template => thesauris.templateToThesauri(template, req.language, req.user))
.then((templateTransformed) => {
req.io.sockets.emit('thesauriChange', templateTransformed);
})
.catch(next)
import Joi from 'joi';
import JoiObjectId from 'joi-objectid';
Joi.objectId = JoiObjectId(Joi);
const email = Joi.string()
.min(3)
.max(255)
.email()
.required()
.label('Email');
const username = Joi.string()
.alphanum()
.min(4)
.max(30)
.required()
.label('Username');
const name = Joi.string()
/** @format */
import Joi from 'joi';
import objectId from 'joi-objectid';
import createError from './Error';
Joi.objectId = objectId(Joi);
export default (schema, propTovalidate = 'body') => (req, _res, next) => {
const result = Joi.validate(req[propTovalidate], schema);
if (result.error) {
next(createError(result.error.toString(), 400));
}
if (!result.error) {
next();
}
};