I try to make a query with mongoose with this :
api.get('/', authenticate, async function (req, res) {
let adminState = await isAdmin(req.user.id)
if (adminState) {
console.log("test 0")
let query = User.find().sort('username', 1).skip(req.query.skip || 0).limit(req.query.limit || 20)
console.log("test 1")
try {
var users = await query.exec()
} catch (err) {
res.status(500).json({ error: "..."})
}
} else {
res.status(401).json({ error: '...'})
}
})
async function isAdmin(id) {
var testAdmin = false
currentUser = await User.findById(id)
if (currentUser && currentUser.role === "Administrateur") {
testAdmin = true
}
return testAdmin
}
However when in postman when I do a GET request to the following url : 'http://localhost:3000/api/users?skip=0&limit=10' my server print the console.log('test 0') and do not continue further with the console.log("test 1"). How could I fix this ?