熊谷洸介(Kousuke Kumagai) 6 лет назад
Родитель
Сommit
366e4541c4
1 измененных файлов с 29 добавлено и 0 удалено
  1. 29 0
      src/server/util/importer.js

+ 29 - 0
src/server/util/importer.js

@@ -16,6 +16,14 @@ module.exports = (crowi) => {
   const importer = {};
   let esaClient = {};
 
+  const { check, validationResult } = require('express-validator/check');
+
+  const actions = {};
+  const api = {};
+
+  actions.api = api;
+  api.validators = {};
+
   /**
    * Initialize importer
    */
@@ -184,5 +192,26 @@ module.exports = (crowi) => {
   importer.initializeEsaClient();
   importer.initializeQiitaClient();
 
+  api.validators.add = function() {
+    const validator = [
+      check('esaAccessToken').exists(),
+      check('esaTeamName').exists(),
+      check('qiitaAccessToken').exists(),
+      check('qiitaTeamName').exists(),
+    ];
+    return validator;
+  };
+
+  api.add = async function(req, res) {
+    const { validationResult } = require('express-validator/check');
+
+    const errors = validationResult(req.check);
+    if (!errors.isEmpty()) {
+      // return res.json(ApiResponse.error('Invalid comment.'));
+      // return res.status(422).json({ errors: errors.array() });
+      return res.json(ApiResponse.error('空欄の項目があります'));
+    }
+  };
+
   return importer;
 };