Procházet zdrojové kódy

refactor ApiV3FormValidator

Yuki Takei před 5 roky
rodič
revize
361a8c7e22
1 změnil soubory, kde provedl 14 přidání a 22 odebrání
  1. 14 22
      src/server/middlewares/ApiV3FormValidator.js

+ 14 - 22
src/server/middlewares/ApiV3FormValidator.js

@@ -3,28 +3,20 @@ const { validationResult } = require('express-validator/check');
 
 const ErrorV3 = require('../models/vo/error-apiv3');
 
-class ApiV3FormValidator {
-
-  constructor(crowi) {
-    return (req, res, next) => {
-      logger.debug('req.query', req.query);
-      logger.debug('req.params', req.params);
-      logger.debug('req.body', req.body);
-
-      const errObjArray = validationResult(req);
-      if (errObjArray.isEmpty()) {
-        return next();
-      }
-
-      const errs = errObjArray.array().map((err) => {
-        logger.error(`${err.location}.${err.param}: ${err.value} - ${err.msg}`);
-        return new ErrorV3(`${err.param}: ${err.msg}`, 'validation_failed');
-      });
-
-      return res.apiv3Err(errs);
-    };
+module.exports = () => (req, res, next) => {
+  logger.debug('req.query', req.query);
+  logger.debug('req.params', req.params);
+  logger.debug('req.body', req.body);
+
+  const errObjArray = validationResult(req);
+  if (errObjArray.isEmpty()) {
+    return next();
   }
 
-}
+  const errs = errObjArray.array().map((err) => {
+    logger.error(`${err.location}.${err.param}: ${err.value} - ${err.msg}`);
+    return new ErrorV3(`${err.param}: ${err.msg}`, 'validation_failed');
+  });
 
-module.exports = ApiV3FormValidator;
+  return res.apiv3Err(errs);
+};