Instantly share code, notes, and snippets.

Embed
What would you like to do?
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