I have an array of objects. I have to check each object trough an API call to see if the object is eligible for a certain promo. What is the best way to keep calling the API with objects until the last object is called in which the observable should return false, or one of the objects get a true state from the API?
At the moment I have this as code but it feels like there should be a better way with RxJS operators.
checkProductForPromo(items: []) {
const promoChecker$ = new EventEmitter<boolean>();
items.forEach((item, key, arr) => {
// This does a HTTP callback to the API
this.ApiService.getProductInformation(item).subscribe(
(product) => {
// Based on some properties this will return true or false of the product is eligible for the promo.
if (product.isEligibleForPromo()) {
promoChecker$.emit(true);
} else if (Object.is(arr.length - 1, key)) {
promoChecker$.emit(false);
}
}
);
});
return promoChecker$;
}