Skip to content

Instantly share code, notes, and snippets.

@Daniel1984
Created January 10, 2021 15:39
Show Gist options
  • Save Daniel1984/ad72bb888a384794bc21d9bb76e2f97e to your computer and use it in GitHub Desktop.
Save Daniel1984/ad72bb888a384794bc21d9bb76e2f97e to your computer and use it in GitHub Desktop.
// middleware/validateBodyParams.js
const validId = require('./validId');
module.exports = (req, res, next) => {
const {
account_id: accId,
currency,
} = req.body;
if (!accId || !currency) {
const err = new Error('missing body params');
err.status = 412;
return next(err);
}
if (!validId(accId)) {
const err = new Error('invalid id');
err.status = 400;
return next(err);
}
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment