I have two service calls. One which returns a list of products and the other one which returns a list of inventory for those products.
My requirement is to merge these two calls so that I can display them in a table. That is a product along with its current inventory.
I am really lost as to how I can combine these two separate service calls. Both have sku has common column name.
service call 1 product
getProducts() {
this.http
.get<{ message: string; products: any }>(
'http://localhost:3000/api/products'
)
.pipe(
map(productData => {
return productData.products.map(product => {
return {
sku: product.sku,
style_code: product.style_code,
id: product._id
};
});
})
)
.subscribe(transformedProducts => {
this.products = transformedProducts;
this.productsUpdated.next([...this.products]);
});
}
service call 2, both have sku in common
getInventory() {
this.http
.get<{ message: string; inventory: any }>(
'http://localhost:3000/api/inventory'
)
.subscribe(inventoryData => {
this.inventory = inventoryData.inventory;
this.inventoryUpdated.next([...this.inventory]);
});
}