this.httpService
.getCustomer(id)
.pipe(
switchMap((customerObj) => this.httpService.getCustomerAccount(customerObj.account_id)),
switchMap((accountObj) =>
this.httpService.getAccountHoliday(accountObj.holiday_id),
),
)
.subscribe((holidays: Holiday[]) => {
for (const holiday of holidays) {
this.httpService.getDestination(holiday.dest_id).subscribe((destination) => {
if (holiday.identifier === destination.name) {
console.log(holiday);
}
});
}
});
I want to do something like this
this.httpService
.getCustomer(id)
.pipe(
switchMap((customerObj) => this.httpService.getCustomerAccount(customerObj.account_id)),
switchMap((accountObj) =>
this.httpService.getAccountHoliday(accountObj.holiday_id),
),
filter(holiday => this.httpService.getDestination(holiday.dest_id).name === holiday.identifier)
)
.subscribe((holiday: Holiday[]) => {
for (const holiday of holidays) {
console.log(holiday);
}
});
That is, merge the logic of for loop with the overservables i.e I need to filter out the holidays before I subscribe. How can I do this?