Return promise inside Observable

Viewed 5932

I've an Angular app using angularfire2 and I'm using a method which removes some information from a few different tables in firebase.

removeTeam(key: string) {
    const dataToRemove = {};
    dataToRemove[`teams/${key}`] = null;

    this.findMembersInTeam(key).subscribe(members => {
      members.forEach(member => {
        dataToRemove[`members/${member}/teams/${key}`] = null;
      });

      this.sdkDB.update(dataToRemove);
    });
  }

So what this does, basically is remove /teams/ and also, for every member in the team, remove the team, so remove /members//teams/.

What I do is retrieve the list of members inside a team, and as this is an observable, inside the subscribe I compose the "query" and execute it with this.sdkDB.update(dataToRemove)

This last method returns a Promise, and that is what I want to return as the result of the method removeTeam, is there a way to do that?

Thanks

2 Answers
Related