I have been making an API server with feathers. I have two mongoose services. Now my requirement is I want one API that has a result of both services. Let's say product-master and product are two services. The output I want is to merge both services.
To accomplish this I found one way is hook. So I tried this.
module.exports = function () {
return function (hook) {
let Product = hook.app.service('product').Model;
return new Promise(function(resolve, reject){
Product.find({}, function(err, products) {
var productMap = [];
products.forEach(function(product) {
productMap.push(products);
});
res.send(productMap);
console.log(productMap);
resolve(hook);
});
});
};
};
Now I called the hook on before find method of product-master But I don't understand how to merge the records of product to product-master service.
And one more thing is how to create a one different API that has a merged result and custom route like http://localhost:3030/products.
Update
I found one post on stackoverflow, this might be helpful.