How to unwrap an observable inside a map in rxjs?

Viewed 188

How can I unwrap the observable (this.fireStore.getExtras(v["extrasId"])) inside the following map?

    this.authService
      .getUser()
      .pipe(
        flatMap((val) => this.fireStore.getItems(val.uid)),
        map((val) =>
          val.map((v) => ({ // this is regular array.map
            ...v,
            extras: {
              ...v["extras"],
              url: (this.fireStore.getExtras(v["extrasId"])).url // this is an observable. I want it to be unwrapped inside here itself,
            },
          }))
        )
      )

this is the inner observable to be unwrapped (this.fireStore.getExtras(v["extrasId"])). I tried flatMap but it is returning the function itself ..., url: flatmap() => ...

1 Answers

Untested

this.authService.getUser().pipe(
    flatMap(val => this.fireStore.getItems(val.uid)),
    switchMap(val => {
      return forkJoin(val.map(v => this.fireStore.getExtras(v.extrasId).pipe(map(x => ({...v, extras: {...v.extras, url: x.url}}))))),
    }),
);
Related