Created
June 21, 2015 06:48
-
-
Save royhowie/6c81843dfb796f6c200d to your computer and use it in GitHub Desktop.
directly return promise or…? (which is better?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userSchema.methods.changePassword = function (password) { | |
// option 1 | |
return new Promise((resolve, reject) => { | |
let evaluatePassword = passwordStrength(password) | |
if (evaluatePassword.state) { | |
return this.generateHash(password).then((hash) => { | |
this.password = hash | |
return this | |
}) | |
} else { | |
throw new Error(evaluatePassword.message) | |
} | |
}) | |
// option 2 | |
let evaluatePassword = passwordStrength(password) | |
if (evaluatePassword.state) { | |
return this.generateHash(password).then((hash) => { | |
this.password = hash | |
return this | |
}) | |
} else { | |
throw new Error(evaluatePassword.message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment