I want a function that'll return weather a user exists or not by querying mysql db. I used callback to return a value. I wrote the following code. But it's not working and calling doesUserExist function returns "undefined". I assume there is an asynchronous execution issue.
Kindly note, db refers to sql connection.
doesUserExist = (email) => {
return resultStatus = doesRecordExist ('email_id', email, (queryResult) => {
if (queryResult > 0) { return true } else { return false }
})
}
doesRecordExist = (searchField, searchString, callback) => {
let query = "SELECT * FROM users WHERE " + searchField + " = '" + searchString + "';"
db.query (query, (err, result) => {
callback(result.length)
})
}