Upload files to 'helpers'
This commit is contained in:
parent
a8c710960e
commit
a2422d3da8
|
@ -0,0 +1,50 @@
|
|||
const Joi = require('joi');
|
||||
// validation does not work well prevents parameters from being entered into the database
|
||||
module.exports = {
|
||||
validateParam: (schema, name) => {
|
||||
return (req, res, next) => {
|
||||
const result = Joi.validate({ param: req['params'][name] }, schema);
|
||||
if (result.error){
|
||||
return res.status(400).json(result.error);
|
||||
} else {
|
||||
if (!req.value)
|
||||
req.value = {};
|
||||
|
||||
if (!req.value['params'])
|
||||
req.value['params'] = {};
|
||||
|
||||
req.value['params'][name] = result.value.param;
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
// Work but for any rasons not implements
|
||||
validateBody: (schema) => {
|
||||
return (req, res, next) => {
|
||||
const result = Joi.validate(req.body, schema);
|
||||
if (result.error) {
|
||||
return res.status(400).json(result.error);
|
||||
} else {
|
||||
if (!req.value)
|
||||
req.value = {};
|
||||
|
||||
if (!req.value['body'])
|
||||
req.value['body'] = {};
|
||||
|
||||
req.value['body'] = result.value;
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
schemas: {
|
||||
serieSchema: Joi.object().keys({
|
||||
title: Joi.string().optional(),
|
||||
synopsis: Joi.string().optional()
|
||||
}),
|
||||
|
||||
idSchema: Joi.object().keys({
|
||||
param: Joi.string().regex(/^[0-9a-fA-F]{24}$/).required()
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue