mizozobu 6 лет назад
Родитель
Сommit
a7ca99db5c
1 измененных файлов с 7 добавлено и 18 удалено
  1. 7 18
      src/server/routes/apiv3/import.js

+ 7 - 18
src/server/routes/apiv3/import.js

@@ -92,7 +92,12 @@ module.exports = (crowi) => {
    *          content:
    *            application/json:
    *              schema:
-   *                type: object
+   *                properties:
+   *                  result:
+   *                    type: array
+   *                    items:
+   *                      type: object
+   *                      description: collectionName, insertedIds, failedIds
    */
   router.post('/', async(req, res) => {
     // TODO: add express validator
@@ -115,7 +120,7 @@ module.exports = (crowi) => {
       // validate with meta.json
       importService.validate(meta);
 
-      const results = await Promise.all(filteredFileStats.map(async({ fileName, collectionName, size }) => {
+      const result = await Promise.all(filteredFileStats.map(async({ fileName, collectionName, size }) => {
         const Model = growiBridgeService.getModelFromCollectionName(collectionName);
         const jsonFile = importService.getFile(fileName);
 
@@ -134,22 +139,6 @@ module.exports = (crowi) => {
         };
       }));
 
-      // convert to
-      // {
-      //   [collectionName1]: {
-      //     insertedIds: [...],
-      //     failedIds: [...],
-      //   },
-      //   [collectionName2]: {
-      //     insertedIds: [...],
-      //     failedIds: [...],
-      //   },
-      // }
-      const result = {};
-      for (const { collectionName, insertedIds, failedIds } of results) {
-        result[collectionName] = { insertedIds, failedIds };
-      }
-
       // TODO: use res.apiv3
       return res.send({ ok: true, result });
     }