Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created May 26, 2018 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/826ea36aef7424279ed9aaa1a2ab4377 to your computer and use it in GitHub Desktop.
Save uno-de-piera/826ea36aef7424279ed9aaa1a2ab4377 to your computer and use it in GitHub Desktop.
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