I need to return a boolean value from the second function of my code below. However, returning isValidOrg
gives me Promise { <pending> }
while console.logging the variable gives me the answer I need. Is there any possibility to return 0 or 1 in my case?
const GetOrganization = userId => {
return User.aggregate([
{ $match: { _id: mongoose.Types.ObjectId(userId) } },
{
$project: {
_id: 0,
organization: 1
}
}
])
}
async req => {
const token = req.headers['authorization'].substr(7);
const secret = req.headers['x-client-secret'];
const xOrg = req.headers['x-organization']
const { _id } = jwt.verify(token, secret)
const isValidOrg = await GetOrganization(_id).then(res => {
return xOrg !== res[0].organization ? 0 : 1
})
console.log(isValidOrg)
return isValidOrg // <-- This line here returns Promise { <pending> }, I need 0 or 1
}