Bring only firebase-specific data

Asked

Viewed 180 times

0

Well, I’m trying to develop an app with Ionic 3 and Firebase. But I’m having problems. You are bringing all the orders, for all users (getAll). I wanted to know the correct way for me to bring only the user requests themselves;

  getAll() {
return this.db.list('pedidos', ref => ref.orderByChild('name'))
  .snapshotChanges()
  .map(changes => {
    return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));

  })

}

  • Tell us which Firebase product you’re using (example: Realtime Database) and an example of how your data is organized.

  • Realtime Database

  • { "requests" { "-Lmmaryymarcdemmdpjm" { "name" "Product1", "tel" : "1234" }, "-Lmmawnotnq8gnk9uww5" : { "name" "Product2", "tel" "321" } } ;}

1 answer

0

Try to include the user id in the function this way:

getListaUsuario() {
    var userId = firebase.auth().currentUser.uid;
    return firebase.database().ref('/pedidos/' + userId).once('value').then(function(snapshot) {
       return snapshot.val();
    });
}
  • It gives error because it expects 2 arguments only

  • I edited the answer. Check if this way you get the result of each user.

  • I have a var like this: requests: Observable<any>; which takes this function that you gave me. It is called in the menu class constructor. It is not accepting, and is giving this error : Uncaught (in Promise): Typeerror: Cannot read Property 'uid' of null Typeerror: Cannot read Property 'uid' of null at Pedidoprovider.webpackJsonp.252.PedidoProvider.getListaUsuario

  • At the beginning of the function, check for authenticated user. Change the start to if(firebase.auth().currentUser != null){ var userid = firebase.auth().currentUser.uid; Return ... }

  • Property 'snapshotChanges' does not exist on type '(snapshot: any) => any'.

  • You can replace the content of your function by return snapshot.val();. I edited the answer again.

  • He brings nothing to the screen

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.