i am newbie on this.
My problem is when I tried to return array full of values, it returned empty.
I faced some weeks before and I solved it, declaring the map as a const and returning its value in a function... but I can't remeber how I did it.
This is my code:
module.exports.deleteLockedEmail = (req, res, next) => {
const maxDateAd = new Date().getTime() - 2592000000;
const adIdsToDelete = [];
Admin.find({})
.then(emailLocked => {
const mapToLockedEm = emailLocked.map(element => {
return User.findOne({email:element.email})
.then(userLocked => {
return adIdsToDelete.push(userLocked)
})
.catch(error => console.log(error))
})
return mapToLockedEm
})
.catch(error => console.log(error))
cron.schedule("* * * * *", function() {
console.log("running a task every minute => delete locked ads");
});
}
How can I fill this array?
adIdsToDelete = [];
Promise.all