From 5dff4be2b4f7ac6d8339468d4a038e29911c7679 Mon Sep 17 00:00:00 2001 From: Juarez Filho Date: Sat, 5 May 2018 01:49:16 +0100 Subject: [PATCH] fix(challenge): Displaying only the notes which you are the owner --- .../notes-list/notes-list.component.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/notes/components/notes-list/notes-list.component.ts b/src/app/notes/components/notes-list/notes-list.component.ts index 59e18cb..d89a0d2 100644 --- a/src/app/notes/components/notes-list/notes-list.component.ts +++ b/src/app/notes/components/notes-list/notes-list.component.ts @@ -3,6 +3,7 @@ import { Observable } from 'rxjs/Observable'; import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; import { Note } from '../../models/note.model'; +import { AuthService } from '../../../core/auth.service'; @Component({ selector: 'app-notes-list', @@ -13,17 +14,20 @@ export class NotesListComponent implements OnInit { notes$: Observable; constructor( - private afs: AngularFirestore - ) { } + private afs: AngularFirestore, + private authService: AuthService + ) {} ngOnInit() { - this.notesCollection = this.afs.collection('notes'); - this.notes$ = this.notesCollection.snapshotChanges().map(actions => { - return actions.map(a => { - const data = a.payload.doc.data() as Note; - const id = a.payload.doc.id; - return { id, ...data }; - }); + this.authService.authState$.subscribe(authUser => { + this.notesCollection = this.afs.collection('notes', ref => ref.where('owner.id', '==', authUser.uid)); + this.notes$ = this.notesCollection.snapshotChanges().map(actions => { + return actions.map(a => { + const data = a.payload.doc.data() as Note; + const id = a.payload.doc.id; + return { id, ...data }; + }); + }); }); }