Here are the service calls that I have available:
productService.GetAllProducts()
productService.DeleteProduct()
productService.GetCategories()
productService.DeleteCategory()
In pseudo code, I need to perform the following steps in my component:
Retrieve a list of products using productService.GetAllProducts().
Iterate through the product list and call productService.DeleteProduct() for each product.
After confirming the successful deletion of all products (due to database constraints), I must then get a list of categories using productService.GetCategories(). Iterate through each category and call productService.DeleteCategory().
I understand that having better backend calls for bulk deletes would make my life easier, but unfortunately, I do not have this option. Therefore, I must follow the process of retrieving a list, iterating through it, and deleting each item individually.
Is it feasible to achieve my goal using flatMap and the observable complete parameter? My main challenge lies in determining when all products have been deleted before moving on to search for and delete all categories.