Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.parameterPermitter = function ({ params = [] }) {
- if (!Array.isArray(params)) throw new Error(`Request Parameter ${params} is invalid parameters array`)
- return function (req, res, next) {
- res.locals.permitted = {}
- params.forEach((param) => {
- if (!req.body.hasOwnProperty(param)) throw new Error(`${param} is required`)
- res.locals.permitted[param] = req.body[param]
- })
- next()
- }
- }
- /**
- * Parameter Permitter Example
- */
- /*
- router.post('/', paramsPermitter({
- params: ['world']
- }), function (req, res, next) {
- res.json(res.locals.permitted)
- });
- */
Add Comment
Please, Sign In to add comment