Допустим, у меня есть следующая структура, это означает, что у пользователя есть и массив объектов, содержащий ссылки на группы. Мне нужно получить одну наблюдаемую для массива ссылочных групп. Как я могу это сделать? Я пробовал много разных способов, но никто не прав.

Вот что я придумал:
export interface Group {
students: DocumentReference[];
title: string;
}
@Injectable()
export class GroupsService {
constructor(private afs: AngularFirestore, private tutorsService: TutorsService) { }
getCurrentTutorGroups(): Observable<Group[]> {
return this.tutorsService.tutor.pipe(
map(tutor => {
return tutor.groupSubjects.map(groupSubject => groupSubject.group.get());
}),
mergeMap(group => fromPromise(group)),
map(group => group.data() as Group)
);
}
}
GroupSubjects {
group: DocumentReference;
subject: DocumentReference;
}
interface Tutor extends User {
groupSubjects: GroupSubjects[];
}
@Injectable()
export class TutorsService {
tutor: Observable<Tutor>;
constructor(private afs: AngularFirestore, private authService: AuthService) {
this.tutor = this.authService.user.map((user: User) => {
return {...user} as Tutor;
});
}
}
export interface User {
uid: string;
email: string;
name: string;
role: string;
}
@Injectable()
export class AuthService {
user: Observable<User | null>;
constructor(private afAuth: AngularFireAuth,
private afs: AngularFirestore) {
this.setUser();
}
private setUser() {
this.user = this.afAuth.authState
.switchMap((user) => {
if (user) {
return this.afs.doc<User>(`users/${user.uid}`).snapshotChanges().map(action => {
return {uid: action.payload.id, ...action.payload.data()};
});
} else {
return Observable.of(null);
}
});
}
}
Мне нужна функция getCurrentTutorGroups для возврата наблюдаемой типа Group [].