Procházet zdrojové kódy

improve a conditional branch

WNomunomu před 2 roky
rodič
revize
6e78fc1a37
1 změnil soubory, kde provedl 8 přidání a 3 odebrání
  1. 8 3
      apps/app/src/server/models/user.js

+ 8 - 3
apps/app/src/server/models/user.js

@@ -145,11 +145,16 @@ module.exports = function(crowi) {
   }
   }
 
 
   userSchema.methods.isUniqueEmail = async function() {
   userSchema.methods.isUniqueEmail = async function() {
-    const User = this.model('User');
+    const query = this.model('User').find();
 
 
-    const userData = await User.findOne({ email: this.email });
+    const count = await query.count((
+      {
+        username: { $not: this.username },
+        email: this.email,
+      }
+    ));
 
 
-    if (userData != null && this.username !== userData.username) {
+    if (count > 0) {
       return false;
       return false;
     }
     }
     return true;
     return true;