In my current project, I am working with an Angular application that receives a collection from Firebase (Observable<any[]>). For each element in this collection, I need to create a new object by combining the original value with information from another Firebase collection.
getLoans(loanStatus: boolean){
return this.afs.collection<any>('loans', ref => ref.where('returned', '==', loanStatus)).valueChanges()
.pipe(
map(loans => loans.map(loan => ({...loan, userCompleteInfo: this.fetchUserInfo(loan.user).subscribe(data => {return data;})}))),
tap(data => console.log(data))
);
fetchUserInfo(userId: string){
console.log(userId);
try{
return this.afs.doc<any>('users/' + userId).valueChanges().pipe(
tap(user => console.log(user))
);
}
catch(error) {
console.log(error);
}
}
I have experimented with various iterations of the code above but haven't been successful. The getLoan() method needs to return an observable<any[]>. Thank you for your assistance,