Skip to content

Instantly share code, notes, and snippets.

@robwormald robwormald/q.js
Last active Aug 29, 2015

Embed
What would you like to do?
angular.module('LoanManager',function(LoanFactory){
function updateLoansData(response){
var allLoans = response.data.data;
return $q.all(allLoans.map(updateLoanData));
}
function updateLoanData(loan){
return $q.all({
need_vote: getPendingVotes(loan),
has_comment: getPendingComments(loan)
})
.then(function(updatedData){
angular.extend(loan,updatedData);
return loan;
})
}
function getPendingVotes(loan){
return LoansFactory.getPendingVotes(loan.id)
.then(function(response){
return (response.data.data.length === 0);
});
}
function getPendingComments(loan){
return LoansFactory.getPendingVotes(loan.id)
.then(function(response){
return (response.data.data.length === 0);
});
}
//PUBLIC API
return {
getLoansWithExtraData: function(){
return LoansFactory.getLoans().then(updateLoansData);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.