1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 11:39:36 +02:00
flame/middleware/requireBody.js

14 lines
334 B
JavaScript
Raw Normal View History

2021-11-10 16:14:22 +01:00
const ErrorResponse = require('../utils/ErrorResponse');
const requireBody = (keys) => (req, res, next) => {
const missing = keys.filter((key) => !Object.keys(req.body).includes(key));
if (missing.length) {
return next(new ErrorResponse(`'${missing[0]}' is required`, 400));
}
next();
};
module.exports = requireBody;