mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Add some method in firebaseService
This commit is contained in:
@@ -54,14 +54,14 @@ class FirebaseService {
|
||||
onValue(
|
||||
ref(this.db, path),
|
||||
(snapshot) => {
|
||||
let result = false;
|
||||
let result;
|
||||
|
||||
// snapshot is a type of data by Firebase define
|
||||
snapshot.forEach((childSnapshot) => {
|
||||
const data = childSnapshot.val();
|
||||
|
||||
if (data[property] === value) {
|
||||
result = true;
|
||||
result = childSnapshot.key;
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user