I'm currently using switchMap and combineLatest to change one of my properties from a reference to a string. I setup a custom pipe (refPipe) that takes a reference and returns an observable of that reference. The below method works just fine but I have another property (data.employees) that is an array of references. How can I iterate through that array and convert it into an array of employee objects in this case?
To clarify, I normally use my ref pipe in the html along with async but this does not work when it comes to filtering and sorting in a table so I'm mapping the data differently before I pass it to the table.
getClientEvents(): Observable<Event[]> {
const eventsCollection = this.afs.collection<Event>('events');
return eventsCollection.snapshotChanges().switchMap(events => {
let arrayOfObservables = events.map(e => {
const data = e.payload.doc.data() as Event;
const id = e.payload.doc.id;
return this.refPipe.transform(data.item).map(item => {
data.item = item.name;
data.employees // My array of references that I need to convert
return { id, ...data };
});
});
return Observable.combineLatest(arrayOfObservables);
});
}