Example #1
0
		return new Promise((resolve) => {
			firebase.database()
				.ref(`/${query.db}`)
				.orderByChild("inhdd")
				.equalTo(1)
				.on("value", (data) => resolve(this.objectToArray(data.val())));
		});
Example #2
0
		return new Promise((resolve) => {
			firebase.database()
				.ref(`/${query.db}`)
				.orderByChild(query.orderKey)
				.limitToLast(query.limit)
				.on("value", (data) => resolve(this.objectToArray(data.val())));
		});
Example #3
0
    constructor(model: BagitModelService)
    {
        this._curFirebaseUser = undefined;
        this._currentUser$    = new BehaviorSubject<User | null>(null);
        this._model = model;

        //
        // Setup to handle authentication state changes.
        //
        this._authInitializedPromise = new Promise((resolve) => {
            // Hang on to the resolve function so that we can call it once the
            // initial auth state change happens.
            this._resolveAuthInitializedPromise = resolve;

        });
        this._firebaseAuth = auth();
        this._firebaseAuth.onAuthStateChanged(this.onAuthStateChanged.bind(this));

        this._isConnected$ = new BehaviorSubject<boolean>(false);
        const connectedRef = database().ref(".info/connected");
        connectedRef.on("value", (snap: database.DataSnapshot | null) => {
            if (snap) {
                this._isConnected$.next(snap.val());
            }
        });
    }
 inject([FirebaseApp, AngularFireDatabase], (_app: firebase.app.App, _db: AngularFireDatabase) => {
   app = _app;
   db = _db;
   ref = firebase.database().ref();
   O = new FirebaseObjectObservable((observer: Observer<any>) => {
   }, ref);
 })();
Example #5
0
	update(params: FirebaseQuery) {
		const { db, id, data } = params;
		if (db && id && data) {
			return Promise.resolve(firebase.database()
				.ref(`/${db}/${id}`)
				.update(data));
		}

		return Promise.reject();
	}
Example #6
0
	hardDelete(params: FirebaseQuery) {
		const { db, id } = params;
		if (db && id) {
			return Promise.resolve(firebase.database()
				.ref(`/${db}/${id}`)
				.remove());
		}

		return Promise.reject();
	}
 it('should call off on all events when disposed', (done: any) => {
   const questionRef = firebase.database().ref().child('questions');
   var firebaseSpy = spyOn(questionRef, 'off').and.callThrough();
   subscription = FirebaseListFactory(questionRef).subscribe(_ => {
     expect(firebaseSpy).not.toHaveBeenCalled();
     subscription.unsubscribe();
     expect(firebaseSpy).toHaveBeenCalled();
     done();
   });
 });
Example #8
0
  addUnreadMessage(workerId: any) {
    let databaseRef = firebase.database().ref(`/workerList/${workerId}`).child('unreadMessages');

    databaseRef.transaction(function (searches) {
      if (searches || searches == 0) {
        searches = searches + 1;
      }
      return searches;
    });
  }
Example #9
0
		const retrieveLast = () => new Promise((resolve) => {
			firebase.database()
				.ref(db)
				.orderByKey()
				.limitToLast(1)
				.once("value")
				.then((finalData: any) => {
					lastIndex = parseInt(Object.keys(finalData.val())[0]);
					resolve();
				});
		});
 beforeEach((done: any) => {
   toKey = (val) => val.key;
   val1 = { key: 'key1' };
   val2 = { key: 'key2' };
   val3 = { key: 'key3' };
   firebase.database().ref().remove(done);
   questions = FirebaseListFactory(`questions`);
   questionsSnapshotted = FirebaseListFactory(`questionssnapshot`, { preserveSnapshot: true });
   ref = questions.$ref;
   refSnapshotted = questionsSnapshotted.$ref;
 });