I am trying to return a list of events liked by a certain user but the array returned by the code seems to always be empty (the return executes before my for loop).
router.route("/app/mylikes").get(async function(req, res, next) {
var mylikes = [];
const likes = await Like.find();
likes.forEach(element => {
bcrypt.compare(req.user.device_uuid, element.device_uuid, function(
err,
isMatch
) {
if (isMatch) {
mylikes.push(element.event_id);
}
});
});
res.send(mylikes);
});
the uuid of the users are hashed within the table so i'm using bcrypt to compare first then i add it to my "mylikes" array.
I'm still a noob when it comes to Promises/await/async so any help is appreciated.