Friday 28 June 2019

Need help with async Firebase function! (See code and comments!)

Hey there! I want to go through each play games user ID, get the data associated with it, and store that data in a dictionary. So it's a dictionary of dictionaries. But I don't know how to wait for these to complete before I return the data from the function. Please help me out if you can! :)exports.getBirdieData = functions.https.onCall(async (data, context) => { let birdieData = {}; // For each play games user ID. data.forEach(function(playGamesUserId) { // Get the user reference associated with the play games user ID. let userRef = usersRef.orderByChild("play_games_user_id").equalTo(playGamesUserId); // Get that user's data. userRef.once("value", function(snapshot) { let userData = {}; userData["u"] = snapshot.child("username").val(); userData["c"] = snapshot.child("colour").val(); userData["h"] = snapshot.child("worn_hat_id").val(); userData["b"] = snapshot.child("worn_chest_id").val(); userData["a"] = snapshot.child("worn_accessory_id").val(); // Put the user's data in the dictionary, where their play games user ID is the key. birdieData[playGamesUserId] = userData; }); }); });

Submitted June 29, 2019 at 05:19AM by enexorb

No comments:

Post a Comment