-
-
Save uno-de-piera/826ea36aef7424279ed9aaa1a2ab4377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import {AngularFirestore, AngularFirestoreCollection} from 'angularfire2/firestore'; | |
import * as faker from 'faker'; | |
type todosCollection = AngularFirestoreCollection<any[]>; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AfireService { | |
constructor( | |
private afs: AngularFirestore, | |
) {} | |
all (): todosCollection { | |
return this.afs.collection('todos'); | |
} | |
add (todoText: string): Promise<any> { | |
const id = faker.random.alphaNumeric(16); | |
const data = { | |
id, | |
todo: todoText | |
}; | |
return this.afs.doc(`/todos/${id}`).set(data); | |
} | |
remove (id: string): Promise<any> { | |
return this.all().doc(id).delete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment