I'm trying to execute certain function depending on what I get from my database in app.rutine here:
return Promise.all(finalApps.map(app => {
return counts.push(setRutine(**app.rutine**));
}))
And the trying to push the return of the function inside the counts Array as shown
But I keep getting Promise { } or Promise { undefined }
This is the setRutine async function:
async function setRutine(nameF) {
if(nameF == "countUsers") {
console.log("YES; IT IS");
await countUsers().then((count) => {
console.log("FROM IF STATEMENT: " + count);
return count;
})
} else {
return "";
}
}
And this is the countUsers() function it calls if the info it got from the db is countUsers that returns a Promise
function countUsers() {
var db = admin.firestore();
var usersRef = db.collection('users');
var count = {};
return new Promise ((resolve, reject) => {
return usersRef.get().then(function(querySnapshot) {
count.size = querySnapshot.size;
count.id = "1";
})
.then(() => {
console.log("FROM countFunction: " + count);
resolve(count);
})
.catch((error) => {
reject(error);
})
});
}
Thank you for any help!