-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.insert
is returning a Promise? These three little dots underneath theawait
indicates 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
insert
that you shared, you need to return a file when the callback.query
is completed.– Rafael Tavares
I will edit my question just a moment
– Vinicius Caetano