Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active August 29, 2015 14:11
Show Gist options
  • Save robwormald/035598400ba80431ab71 to your computer and use it in GitHub Desktop.
Save robwormald/035598400ba80431ab71 to your computer and use it in GitHub Desktop.
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