import firebase from "firebase" ; import { Guid } from "guid-typescript" ; import { IDatabaseModelBase } from './DatabaseModelBase' ; export abstract class FirestoreService < T extends IDatabaseModelBase > { constructor ( private collection ) { } public async Get ( id ) { const qry = await firebase . firestore ( ) . collection ( this . collection ) . doc ( id ) . get ( ) ; return < T > qry . data ( ) ; } public async GetAll ( ) { const qry = await firebase . firestore ( ) . collection ( this . collection ) . get ( ) ; const items = new Array < T > ( ) ; qry . forEach ( ( item ) => { items . push ( < T > item . data ( ) ) ; } ) ; return items ; } public async Save ( item ) { return new Promise < T > ( async ( coll ) => { item . ServerID = Guid . create ( ) . toString ( ) ; await firebase . firestore ( ) . collection ( this . collection ) . doc ( item . ServerID ) . set ( item ) ; coll ( item ) ; } ) ; } }