What I am trying to achieve is push a few http request observables in an array and then combine all the responses and return with a single observable.
Since all the http requests resolve with the same type 'User', I just want to wait for all of them to resolve and then I can return a single observable with all Users from getUsers() function.
I'm stuck at the return merge(observableRequests) part as I can't get the return type right and I'm not too versed in Rxjs functions.
Here are my three related functions.
getMyUser(): Observable<User> {
return this.service.get(`${this._userPath}me`).pipe(
map((serviceUser: any) => {
return parseUser(serviceUser);
}));
}
getUsers(): Observable<User[]> {
return this.getMyUser()
.pipe(switchMap((user: User) => {
const activeProvidersIds = this._getActiveProvidersIds(user.providers);
const observableRequests = activeProvidersIds.map((id: number) => this.getUserRequest(id));
return merge(observableRequests);
}));
}
getUserRequest(facDbk: number): Observable<User[]> {
return this.service.get(`${this._providerPath}${facDbk}/users`).pipe(
map((serviceUsers: any) => {
return parseUsers(serviceUsers);
})
);
}
Any help is appreciated.