Closed rusmichal closed 7 years ago
Sequelize use Bluebird for promise implementation, you can use spread method and in 2nd paramter you will get updated object.
If you dont understand how Promise works consider reading this http://bluebirdjs.com/docs/why-promises.html
Please study Model API in docs for more information on return types and stuff
Thx.
My solution: // I use repository pattern
userRepo.findById(id).then(user => {
if (user) {
var token = jwt.sign(user.updatedAt, process.env.JWT_SECRET || "xxxxxxx");
userRepo.updateById(req.body, token)
.then(function(user) { return user; })
.spread(function(user, updatedUser) {
res.status(201).send(updatedUser);
})
.catch(error => res.status(400).send(error));
} else {
userRepo.save(req.body)
.then(user => res.status(201).send(user))
.catch(error => res.status(400).send(error));
}
});
I update a user model like that
and I get a result:
I want to get :
How to reach that simple stuff?!