فهرست منبع

return failedToCreateUser

Shun Miyazawa 4 سال پیش
والد
کامیت
d6153fba6a
1فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 13 3
      src/server/models/user.js

+ 13 - 3
src/server/models/user.js

@@ -573,7 +573,8 @@ module.exports = function(crowi) {
     const creationEmailList = emailList.filter((email) => { return existingEmailList.indexOf(email) === -1 });
 
     const createdUserList = [];
-    let failedToCreatetReason;
+    const failedToCreateUserEmailList = creationEmailList;
+    let failedToCreateReason = '';
 
     const promise = creationEmailList.map(async(email) => {
       const user = await this.createUserByEmail(email);
@@ -585,14 +586,23 @@ module.exports = function(crowi) {
         results.forEach((result) => {
           if (result.status === 'fulfilled') {
             createdUserList.push(result.value);
+
+            // remove created user
+            const index = failedToCreateUserEmailList.indexOf(result.value.email);
+            failedToCreateUserEmailList.splice(index, 1);
           }
           else {
-            failedToCreatetReason = result.reason;
+            failedToCreateReason = result.reason;
           }
         });
       });
 
-    return { existingEmailList, createdUserList };
+    const failedToCreateUser = {
+      emailList: failedToCreateUserEmailList,
+      msg: failedToCreateReason,
+    };
+
+    return { existingEmailList, createdUserList, failedToCreateUser };
   };
 
   userSchema.statics.sendEmailbyUserList = async function(userList) {