Advanced promise chaining for AngularJS