With angular 10, in a service I have the method getCurrentUser() that makes an http call to my api to return the current user as observable (with one of the property is "isAdmin:boolean"), and I have this other service where I would like to create the method getAllUsers that would return the list of all users (user[]) also as observable but only if the current user is an admin (user.isAdmin = true). I tried a few stuff with rxjs operators like map, switchMap and flatMap but I can feel that I a am completly mistaken, could you give some hints for this?

Here is what I tried in the second service:

```
@Injectable({
    providedIn: "root",
})
export class BackofficeService {

    constructor(private http: HttpClient, private userService: UserService) {}

    public getAllUsers(): Observable<User[]> {
        this.userService.getCurrentUser().pipe(
            map((user: User) => {
                if (user.roles.includes("admin")) {
                    return this.http.get<User[]>("/api/settings/users/all");
                } else throw new Error("User not admin.");
            })
        );
    }
}

```

I also don't know how to manage the return of getAllUsers() since sometimes it won't return anything if user is not admin. With the simple "else throw new Error()" I got a compiler error because I declared that getAllUsers() should return an Observable.

And then in my component I do:

```
@Component({
    selector: "app-users",
    templateUrl: "./users.component.html",
})
export class UsersComponent implements OnInit {
  public usersList: User[];
  constructor(private boService: BackofficeService) {}

    ngOnInit(): void {
    this.boService
      .getAllUsers()
      .subscribe((users?: User[]) => {
        if(users){
          this.usersList = users;
        }
      })
    }
}

```