She's a bird.
-
There's been some misunderstanding in the promis. Main function
a()
and functionb()
where the database is approached. After functionb()
The result should be transferred toa()
for further processing. But I understand,resolve( b(user) )
Called before it worked.b()
♪ How can we solve the problem?function a(){
var info = {email: 'email@email.ru'}, user = new Promise(function(resolve, reject) { resolve( b(user) ); }); user.then(function(result) { res.send( result ); });
}
function b(params){
model.user.findAll({ where:{ email: params['email'] } }).then(function(user){ return(user); });
}
-
function
b
The Promise can be returned if you add return, so there is no need to create it.a
function a(){
var info = {email: 'email@email.ru'}, user = b(info); user.then(function(result) { res.send( result ); });
}
function b(params){
return model.user.findAll({ where:{ email: params['email'] } }).then(function(user){ return(user); });
}