1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-14 16:59:57 -05:00
shimapan/app/util/verifyBody.js

14 lines
368 B
JavaScript
Raw Normal View History

const verify = require('./verify.js');
2018-08-01 13:07:52 -04:00
// Verifies the entire request body is well formed
2019-01-02 14:27:20 -05:00
const verifyBody = expected => async (req, res, next) => {
try {
await Promise.all(expected.map(e => verify(req.body[e.name], e)));
next();
} catch(err) {
res.status(err.code).json({message: err.message});
}
2019-01-02 14:27:20 -05:00
};
module.exports = verifyBody;