Currently, my code includes an auth.service.ts, crud.service.ts, and a components.ts. Although it functions correctly, it is a hodgepodge of various tutorials and documentation. I am seeking advice on how to streamline the code by centralizing all logic in crud.service.ts using rxjs operators. Ultimately, I aim to return a single observable of fully formatted item collections.
crud.service.ts
getTasks() {
return this.auth.user$.pipe(
switchMap((value: any) => this.db.collection(`users/${value.uid}/tasks`).snapshotChanges())
)
}
component.ts
ngOnInit(): void {
this.fireService.getTasks().subscribe((a: any) => {
this.tasks = []
a.forEach((b: any) => {
let item: any = b.payload.doc.data();
item.id = b.payload.doc.id;
item.defaultState = true
this.tasks.push(item)
})
})
}