Created
December 13, 2014 18:51
-
-
Save geilt/87c63012df038bd633d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adv: { | |
findOne: function(args){ | |
return Loan.findOne(args) | |
.populate('broker') | |
.populate('borrower') | |
.populate('createdBy') | |
.populate('updatedBy') | |
.populate('notes') | |
.populate('investors') | |
.populate('documents') | |
.populate('transactions') | |
.populate('schedule') | |
.then(function(loan){ | |
var industry = Meta.findOne({value: loan.industry, key: 'industry'}); | |
return [loan, industry]; | |
}) | |
.spread(function(loan, industry){ | |
loan.industry = industry; | |
return loan; | |
}) | |
.then( function(loan){ | |
console.log('Loan Investors', Object.keys(_.indexBy(loan.investors, 'id'))); | |
var investors = LoanInvestor.adv.find(Object.keys(_.indexBy(loan.investors, 'id'))) | |
.then(function(result){ | |
return result; | |
}); | |
return [loan, investors]; | |
}) | |
.spread( function(loan, investors){ | |
loan.investors = investors; | |
return loan; | |
}) | |
.then( function(loan){ | |
var notes = LoanNote.adv.find({id: Object.keys(_.indexBy(loan.notes, 'id'))}) | |
.then( function(result){ | |
return result; | |
}); | |
return [loan, notes]; | |
}) | |
.spread( function(loan, notes){ | |
loan.notes = notes; | |
return loan; | |
}) | |
.then( function(loan){ | |
console.log('Loan End Investors'); | |
console.log(loan.investors); | |
console.log('Loan End'); | |
console.log(loan); | |
return loan; | |
}) | |
.catch( function(err){ | |
DebugError('Loan.js adv.findOne', err); | |
}); | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adv: { | |
find: function(args){ | |
return LoanInvestor.find(args) | |
.populate('user') | |
.populate('loan') | |
.populate('schedule') | |
.then(function(investors) { | |
var promises = []; | |
_.forEach(investors, function(investor, index) { | |
var schedule = LoanInvestorSchedule.adv.find({loanInvestor: investor.id}, function(){ | |
investor.schedule = result; | |
}); | |
promises.push(schedule); | |
}); | |
return [investors, Promise.all(promises)]; | |
}) | |
.spread(function(investors, schedule) { | |
return investors; | |
}); | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adv: { | |
find: function(args){ | |
return LoanInvestorSchedule.find(args) | |
.populate('loanInvestor'); | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment