Witajcie, mam problem z funkcją (isAdmin) której zadaniem jest zwracanie wartości true albo false, jednak zwraca ona zawsze wartość "undefined". W czym może tkwić problem?
function isAdmin(req, res) {
dbConnection.getConnection((err, connection) => {
connection.query(`SELECT id FROM users WHERE id = '${req.session.userId}' AND admin = 1`, (err, rows) => {
connection.release();
if (err) throw err;
if (rows.length == 1) return true;
else return false;
});
});
}
exports.getDbTable = (req, res, next) => {
let table = req.params.table;
console.log(isAdmin(req, res)); // undefined
if (isAdmin(req, res) != true && table == "users") return res.status(401).json({error: 6, errorMsg: "Access Denied"});
dbConnection.getConnection((err, connection) => {
connection.query(`SELECT * FROM ${table}`, function (err, rows) {
if (err) throw err;
else {
console.log(rows);
}
connection.release();
});
});
}