Skip to content

Instantly share code, notes, and snippets.

@jongravois
Forked from robwormald/q.js
Last active August 29, 2015 14:12
Show Gist options
  • Save jongravois/1d82bf709f118b45e37b to your computer and use it in GitHub Desktop.
Save jongravois/1d82bf709f118b45e37b to your computer and use it in GitHub Desktop.
angular.module('LoanManager',function(LoansFactory){
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.getPendingComments(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