Skip to content

Instantly share code, notes, and snippets.

@royhowie
Created June 21, 2015 06:48
Show Gist options
  • Save royhowie/6c81843dfb796f6c200d to your computer and use it in GitHub Desktop.
Save royhowie/6c81843dfb796f6c200d to your computer and use it in GitHub Desktop.
directly return promise or…? (which is better?)
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