opt-cc/api/middleware/validators.js

26 lines
516 B
JavaScript

'use strict';
// HTTP status codes by name
const codes = require('../routes/http-codes');
/**
* check if id has valid UUID format
*
* @param {object} req
* @param {function} res
* @param {function} next
* @return {boolean}
*/
const idValidator = (req, res, next) => {
const reqId = req.params.id;
if (!reqId.match(/^[0-9a-fA-F]{24}$/)) {
const err = new Error('Invalid request id format');
err.status = codes.notfound;
return next(err);
}
next();
};
exports.idValidator = idValidator;