Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Loan.destroy({ id: id })
- .then(function(result){
- return LoanInvestor.find({loan: id})
- .then(function(loanInvestors){
- return loanInvestors.map(function(investor){
- return investor.id;
- });
- });
- })
- .then( function(LoanInvestorIds){
- return [
- LoanSchedule.destroy({loan: id}),
- LoanInvestor.destroy({loan: id}),
- LoanInvestorSchedule.destroy({loanInvestor: LoanInvestorIds}),
- LoanNote.destroy({loan: id}),
- LoanDocument.destroy({loan: id}),
- LoanTransaction.destroy({loan: id})
- ];
- })
- .spread( function(schedule, investor, investorSchedule, note, docs, transactions) {
- return result;
- })
- .then( function(result){
- Loan.subscribe(req.socket, id, ['destroy']);
- Loan.publishDestroy(id);
- res.json('Deleted Loan');
- }).error( function(err){
- res.json(409, err);
- });
Advertisement
Add Comment
Please, Sign In to add comment