I have a Workspace model, a Request model... and now a CatalogItem model which needs to combine the two like this:
{
workspace: Workspace
requests: Request[]
}
I'm having a bit of difficulty with how I should create this with a getCatalog(): Observable<CatalogItem[]>
function... which should return a CatalogItem
for each Workspace
, with any associated Request
added to it.
I realize my attempt is way off, but I'm hoping it's enough to help understand my intent:
getCatalog(): Observable<CatalogItem[]> {
return this.http.get<Workspace[]>(`${this.baseUrl}/workspace`).pipe(
switchMap( (ws) => {
return {
workspace: ws,
requests: this.http.get<Request[]>(`${this.baseUrl}/${ws.id}/requests`).subscribe();
}
})
);
//TODO: combine workspace and request create catalog obj
}