-1
I’m with a method in a class that calls the method another class and after that he gives a console.log of the return of this method. But this console.log is executed before the function call causing the result of the console.log be it undefined:
sign(data = {})
{
let result = this.Verify.sign(data)
if(result != 'ok')
{
return 'false'
}
else{
//INSERIR PERSON E USER
let obj = {'desname': data['desname'], 'dtbirth': ''}
this.Query.insert('tb_person', obj)
.then( (response) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})
}
}
async insert(table, obj){
let sql = `INSERT INTO ${table} SET ?`
conect.query(sql, obj, (error, result) => {
if(error)
{
return 'falid'
}
else
{
return 'ok'
}
})
}
That function
Query.insertis returning a Promise? These three little dots underneath theawaitindicates that it has no effect on this code, it would be good to include the code of this function also in your question, and preferably as text, not as image.– Andre
This answers your question? How to adapt a function that only accepts callback to the promise interface in Javascript?
– Rafael Tavares
Read the question I mentioned. Based on the code of
insertthat you shared, you need to return a file when the callback.queryis completed.– Rafael Tavares
I will edit my question just a moment
– Vinicius Caetano