title: Am I using promises correctly?
body: <p>I have the following function (I'm using the <code>Q</code> promise library):</p>
  
  <pre><code>confirmEmail: function(confirmationCode){
      var deferred = q.defer();
  
      User.find({
        where: {confirmation_code: confirmationCode}
      }).then(function(user){
        if(user){
          user.updateAttributes({
            confirmation_code : null,
            confirmed: true
          }).then(function() {
            deferred.resolve();
          });
        }else{
          deferred.reject(new Error('Invalid confirmation code'));
        }
      });
  
      return deferred.promise;
    }
  </code></pre>
  
  <p>I've been reading a bit about the best practices regarding promises e.g. <a href="https://stackoverflow.com/questions/23803743/what-is-the-deferred-antipattern-and-how-do-i-avoid-it">What is the explicit promise construction antipattern and how do I avoid it?</a>
  <a href="http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html" rel="nofollow noreferrer">http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html</a></p>
  
  <p>Have I written the above function so that it is keeping with these practices, or is there a better way?</p>