I think it's bad practice to have different return types. So, this is my function, and I want it to always return a promise.
I tried to simplify the scenario. Let's say I have two lines of products (line X and line Y) and the way I'm retrieving a product by name, from each line is totally different from the other.
Please also note that ideally, I wanted to have a function to "or" two promises and return whichever that resolves successfully. But I couldn't think of a better way to achieve this!
ProductService.findProductByName = function findProductByName(name) {
return LineXService.findOneByName(name) // promise
.then(function _returnProduct(product) {
return product
? product // value
: LineYService.findOneByName(name)); // promise
})
};