Created
July 7, 2014 03:48
-
-
Save kfatehi/80a341f0a92445a41ef1 to your computer and use it in GitHub Desktop.
oh javascript, how you nest so deeply, so easily...
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
function createCardsViaProvider(req, res, next) { | |
var board = req.board; | |
var handler = providers[req.params.provider].cardHandler; | |
var promises = []; | |
Column.findOne({ board: board._id, role: 1 }) | |
.exec(function (err, column) { | |
if (err) { | |
logger.error(err.message); | |
res.send(500); | |
} else { | |
handler.batchImport(board, req.body, function (attributes) { | |
attributes.column = column._id; | |
promises.push(Card.create(attributes)) | |
}, function() { | |
Promise.all(promises).then(function () { | |
Board.update({ _id: board._id }, { columns: board.columns }, function(err) { | |
if (err) { res.send(500, err.message); } | |
else { | |
Board.findOne({ _id: req.params._id }).populate('columns').exec(function(err, board) { | |
if (err) { | |
logger.error(err.message) | |
res.send(500) | |
} else if (board) { | |
Card.populate(board.columns, { path: 'cards' }, function(err) { | |
if (err) { | |
logger.error(err.message); | |
/*lol javascript*/ res.send(500); | |
} else { | |
req.board = board; | |
res.send({ board: { columns: board.columns } }) | |
} | |
}); | |
} else { | |
res.send(404); | |
} | |
}); | |
} | |
}); | |
}); | |
}) | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment