I have this piece of code I'm writing in node.js, and I have a problem.
async function CheckearWhitelist(id) {
const oracheck = ora("Checkeando en la whitelist...").start();
con.connect(function (err) {
if (err) {
oracheck.fail(
"Ha habido un fallo al conectarse a MySQL - Comprueba la conexión"
);
}
con.query(
`SELECT * FROM \`whatsapp\`.\`whitelist\` WHERE \`contacto\` = '${id}'`,
function (err, result, fields) {
if (err) {
oracheck.fail("Fallo de MySQL");
} else if (result == []) {
oracheck.warn("Usuario no encontrado en la whitelist");
return false
} else {
date = new Date();
horas_fecha = date.getHours();
minutos = date.getMinutes();
hora = `${horas_fecha}.${minutos}`;
hora_desb = result[0].hora_desbloqueo;
if (hora_desb == 0) {
oracheck.info("El contacto está en la whitelist indefinidamente");
return true
} else if (hora_desb <= hora) {
oracheck.warn("Usuario no encontrado en la whitelist");
return false
} else {
oracheck.succeed("Resultado Encontrado: ");
return true
}
}
}
);
});
}
CheckearWhitelist("34676654601@c.us").then((value) => console.log(value));
The thing is that if I make console.log(true/false) and not the return, it perfectly works. But when I return true/false, and make a console.log when calling the function, it doesn't work. I hope someone can help me. Thanks