I have an array of marinas, for which I want to make api calls. The Problem is that the result will arrive after, the return. Can anyone help me please?
getAllChangeRequests(): Observable<any> {
console.log('getAllChangeRequests');
this.changeRequestArray = []
this.state.setUpdating(true);
return this.userOrganisationFavouritesFacade.loadAll().pipe(map(async marinas => {
const promises: U2bChangeRequest[][] = []
const test = await Promise.all(marinas.map(marina => {
if (marina.organisation?.bcm_tenant_id) {
console.log('hallo2');
this.getMany((new HttpParams().set('tenantId', `${marina.organisation?.bcm_tenant_id}`))).subscribe(changeRequests => {
console.log(changeRequests);
promises.push(changeRequests)
})
}
}))
console.log(test);
this.state.setChangeRequests(this.changeRequestArray);
this.state.setUpdating(false);
return promises;
}));
}