This function is to detect if there were no errors when deleting the records but I call it from another function like this
if(!deleteAllSectionsPage(123) )
{
//alguna accion.
}
I've got
function deleteAllSectionsPage(idpage)
{
Section.destroy(
{
where : {
page_id: idpage,
status : 1
}
}
).then(section => {
return true
}).catch(function (err) {
return false
});
}
but it does not return the boolean value that is in
).then(section => {
return true
}).catch(function (err) {
return false
});
The truth is I don't know why, I lack knowledge in this type of situation, I've been looking but I can't find it and I'm lost in this. Can someone tell me how I can solve this?
Well I think what you could do is handle it in another way, because you're going to need to return a Promise or Promise.
You need to modify the function to return the Promise:
then the if you would have to handle it in another way:
Here the problem is that you are dealing with Asynchronous Actions, because when making an http query, javascript processes this action in parallel and continues executing the code and in this way asynchronous processes are formed, improving execution efficiency. I recommend you read more about the Promises. You can start here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
I hope this helps you.