I'm new to using the bluebird promise library. And I was wondering if there was a better way to do wrap complex if then branching statements that may or may not require async calls than what I'm currently doing.
example of what I have now:
(function() {
if (a) {
return ModelA.findById(id);
} else if (b) {
return ModelB.findById(id);
} else if (c) {
return ModelC.findById(id);
} else {
return Promise.reject(new Error('a, b, or c must be specified'));
}
})()
.then(function(result) {
if(result == null) {
return new Error('Object not found')
}
result.removedBy = user.id;
result.removedWhen = new Date();
result.inactive = true;
return result.save();
})