I am new to angular and rxjs, I am working on an Angular project and my component has a Behaviour subject declared as follows:
therapySessions: BehaviorSubject<any[]> = new BehaviorSubject([]);
therapySessions is filled with values on the component initialization. My component, however, is not interested in the therapySessions values, but in something called gameSessions. I need these therapySessions loaded in order to be able to obtain the gameSessions, because the service that retrieves the game sessions for me asks for the therapy session id, since one therapy session can have many game sessions.
I understand that it would be much better to have an API that delivers all game sessions, but unfortunately we still dont have that, so in order to get all game sessions, I have to iterate over the therapy sessions and get all game sessions belonging to each therapy session.
This is what the service that obtains game sessions look like:
therapySessionService.getGameSessions(therapySessionSubject, subscriber)
the subscriber must be a behaviour subject that will receive the gameSessions in the internal implementation.
the question is: How can I iterate over the therapy sessions values (that are not subjects), call the service above for each therapy session and pass a subscriber, and finally have all gameSessions available in my component on init? I have to generate charts with their data. I guess it is not a very good design to depend on so many nested subscriptions to finally be able to use the data from the final result, but unfortunately I am not allowed to change the Api's and have to find a work around the existing Api.