데이터베이스에서 특정 데이터를 검색하려면 2 firebase calls
을 실행해야합니다. Once these promises resolve
, 검색된 데이터가있는 다른 함수를 호출하고 싶습니다. 어떻게해야합니까? 아래 Promise.All?
여러 firebase 약속을 실행 한 다음 한 번 완료되면 함수를 실행하십시오
코드와 ..something :
이app.post('/testtwilio', function(req, res) {
//save request variables
var to_UID = req.body.to;
var from_UID = req.body.from;
var experience_id = req.body.exp_id;
//Query firebase and save 'zone_id' which we need later
firebase.database().ref('experiences').child(experience_id).once('value').then((snap) => {
zone_id = snap.val().ZoneID;
});
//Query firebase and save 'from_name' which we need later
firebase.database().ref('users').child(from_UID).once('value').then((snap) => {
from_name = snap.val().Name;
});
//Once we have the two variables returned and saved
//Call a final firebase query and a twilio function with all the recieved data
firebase.database().ref('users').child(to_UID).once('value').then((snap) => {
//Do something with this aggregated data now
client.messages.create({
//blah blah do something with the saved data that we retrieved
var phone = snap.val().Phone;
var msg = from_name + zone_id + from_UID + experience_id
});
});
});