mizozobu 6 лет назад
Родитель
Сommit
73b715c6d4

+ 12 - 1
src/client/js/components/Admin/Import/GrowiZipImportForm.jsx

@@ -49,7 +49,7 @@ class GrowiImportForm extends React.Component {
 
     try {
       // TODO use appContainer.apiv3.post
-      await this.props.appContainer.apiPost('/v3/import', {
+      const { results } = await this.props.appContainer.apiPost('/v3/import', {
         fileName: this.props.fileName,
         collections: Array.from(this.state.collections),
         schema: this.state.schema,
@@ -68,6 +68,17 @@ class GrowiImportForm extends React.Component {
         timeOut: '1200',
         extendedTimeOut: '150',
       });
+
+      for (const { collectionName, failedIds } of results) {
+        if (failedIds.length > 0) {
+          toastr.error(`failed to insert ${failedIds.join(', ')}`, collectionName, {
+            closeButton: true,
+            progressBar: true,
+            newestOnTop: false,
+            timeOut: '30000',
+          });
+        }
+      }
     }
     catch (err) {
       // TODO toastSuccess, toastError

+ 3 - 3
src/server/routes/apiv3/import.js

@@ -93,7 +93,7 @@ module.exports = (crowi) => {
    *            application/json:
    *              schema:
    *                properties:
-   *                  result:
+   *                  results:
    *                    type: array
    *                    items:
    *                      type: object
@@ -120,7 +120,7 @@ module.exports = (crowi) => {
       // validate with meta.json
       importService.validate(meta);
 
-      const result = await Promise.all(filteredFileStats.map(async({ fileName, collectionName, size }) => {
+      const results = await Promise.all(filteredFileStats.map(async({ fileName, collectionName, size }) => {
         const Model = growiBridgeService.getModelFromCollectionName(collectionName);
         const jsonFile = importService.getFile(fileName);
 
@@ -140,7 +140,7 @@ module.exports = (crowi) => {
       }));
 
       // TODO: use res.apiv3
-      return res.send({ ok: true, result });
+      return res.send({ ok: true, results });
     }
     catch (err) {
       // TODO: use ApiV3Error