check-schema.js 706 B

12345678910111213141516171819202122232425
  1. export function checkReqBody(schema, log, path) {
  2. return function checkValid(req, res, next) {
  3. schema.isValid(req.body).then(valid => {
  4. if (valid) {
  5. next();
  6. } else {
  7. res.send(400, { error: 'Bad request' });
  8. log.debug(`Invalid request for route: ${path}, ${JSON.stringify(req.params)}`);
  9. }
  10. });
  11. };
  12. }
  13. export function checkParams(schema, log, path) {
  14. return function checkValid(req, res, next) {
  15. schema.isValid(req.params).then(valid => {
  16. if (valid) {
  17. next();
  18. } else {
  19. res.send(400, { error: 'Bad request' });
  20. log.debug(`Invalid request for route: ${path}, ${JSON.stringify(req.params)}`);
  21. }
  22. });
  23. };
  24. }