Promise All / promiseall
var p = [
models.User.findOne({
where: where,
paranoid: false,
include: [{
model: models.UserState,
required: false
}],
transaction: req.trans
})
];
if(req.slUserExists) {
p.push(
models.Provider.findOne({
where: {
user_id: req.slProfile.user_id
},
transaction: req.trans
})
);
}
Promise.all(p).then(function(result) {
var user =result[0];
if(user) {
req.user = user.toJSON();
if(req.slUserExists) {
if(result[1]) {
req.provider = (result[1]).toJSON();
req.user.provider_id = req.provider.id;
}
req.session = AuthCtrl.getNewSession(req.user, req).session;
req.session = AuthCtrl.saveLoginFull(req.user.id, IP, userAgentId).session;
}
}