Add some method in firebaseService

This commit is contained in:
2023-08-31 11:47:46 +07:00
parent 269cc6a104
commit a5c9e81e1d
@@ -54,14 +54,14 @@ class FirebaseService {
onValue( onValue(
ref(this.db, path), ref(this.db, path),
(snapshot) => { (snapshot) => {
let result = false; let result;
// snapshot is a type of data by Firebase define // snapshot is a type of data by Firebase define
snapshot.forEach((childSnapshot) => { snapshot.forEach((childSnapshot) => {
const data = childSnapshot.val(); const data = childSnapshot.val();
if (data[property] === value) { if (data[property] === value) {
result = true; result = childSnapshot.key;
} }
}); });
resolve(result); resolve(result);
@@ -72,6 +72,20 @@ class FirebaseService {
); );
}); });
} }
getDataFromId(id, path) {
return new Promise((resolve) => {
onValue(
ref(this.db, path + id),
(snapshot) => {
resolve(snapshot.val());
},
{
onlyOnce: true,
},
);
});
}
} }
export default new FirebaseService(); export default new FirebaseService();