The goal of this is for me to grab all the dates from my database, organize them from newest to oldest, grab the information needed from my database in that order and send that client side. The code does work server side and all the information is correct. I just need to send it to my client. My client side receives strings and anything I send, I think the problem is where my returning statement is. Thank you in advanced to whoever attempts to help me.
This is my server side code:
exports.loadNewestPlaylist = functions.https.onCall((request, response) => {
try {
var dates = [];
var Info = [];
var query = admin.database().ref().orderByKey();
query.once("value")
.then(function (snapshot) {
snapshot.forEach(function (snapshot) {
if (dates.indexOf(snapshot.child("Date").val()) > -1) {}
else {
dates.push(snapshot.child("Date").val());
dates.sort(date_sort_asc);
}
});
dates.forEach(function (date) {
query.once("value")
.then(function (snapshot) {
snapshot.forEach(function (snapshot) {
if (date === snapshot.child("Date").val()) {
Info.push(snapshot.child("Url").val(), snapshot.key);
}
});
});
});
return Info;
});
var date_sort_asc = function (date1, date2) {
if (date1 > date2) return 1;
if (date1 < date2) return -1;
return 0;
};
}
catch (error) {
console.error(error);
}
});