Can someone help me modify this code so that it returns an Observable<ApiResponse>
? I'm unsure if my current approach is correct.
private doRequestProducts() {
const sequence$ = this.http.post<ApiResponse>(this.baseUrlOverview, {} { observe: 'response' }).pipe(
switchMap(res => {
if (res.status !== 200) {
throw new Error('Value expected!');
}
const productResponse: productOverviewResponse = {... res.body.data};
const responses: Observable<ApiResponse>[] = [];
productResponse.Products.forEach((item, index) => {
const response: Observable<ApiResponse> = this.http.post<ApiResponse>(this.baseUrlDetail, {
productID: item.productId,
});
responses.push(response);
});
return forkJoin(responses).pipe(
map(d => {
const items: product[] = [];
d.forEach((api) => {
if (api.status === 'ok') {
const invResp: product = {... api.data};
items.push(invResp);
}
});
})
);
}
));
}