Im struggling with this promise
Im working with database calls (db) , so I have delays in my calls. And I cant seem to make calls to this functions await.
async function userExists(id) {
db.query("SELECT * from users where tg_id=" + id).then(res => {
if (res[0] === undefined) {
console.log("we register the user")
db.query("INSERT INTO users (tg_id, balance) VALUES ('" + id + "','100')").then(res => {
return new Promise(resolve => {
resolve(true)
})
}).catch(err => {
console.log(err)
})
} else if (res[0]) {
console.log("It was already registered")
return new Promise(resolve => {
resolve(false)
})
}
}).catch(err => {
console.log(err)
})
}
This is the call, where res is always undefined
bot.command('balance', (ctx) => {
let myId = ctx.update.message.from.id
var existsStatus = ""
userExists(myId).then(res => {
console.log(res) //always undefined
})
})