Hello I'm using sequelize and I would like to make a synchronous query, but this is made asynchronously and return an wrong response. I have this code:
function(user) {
var allow = false;
return User.find({ where: { id: user.id},
include: [{
model: Plan,
attributes: ['id', 'name']
}]
}).then(function(u) {
if(!u) throw new Error("0 user not found");
user = u.dataValues;
var plan = user.plan.dataValues.name;
else if (plan == "Premium") allow = true;
console.log("allow", allow);
return allow;
}).catch(function(error){
console.log("error:::", error);
});
}
And the console.log('allow', allow);
is printing true
but when I call the function, the function is returning false
.
Thanks for help.