Http response not sent in promise chain

P

PierrotDx

Guest
In the code below I do not receive an HTTP response on the front-side although the message 'Hello there' is displayed on the console. Manifestly I am missing something but can someone point it to me?

Also, more generally, I am not sure that chaining then like this is good practice. Is it ok?

exports.updateUserProfile = (req, res) => {
const userId = req.body.id;
const password = req.body.password;
const newIds = req.body.newIds;

userService.isPasswordValid(userId, password)
.then(
isValid => {
if (isValid) {
return isValid;
} else {
return res.status(401).json({
message: 'Invalid password.'
});
}
})
.then(
() => {
return userService.getFieldsToUpdate(newIds);
})
.then(
update => {
console.log('update: ', update);
return User.updateOne(
{ _id: userId },
update
);
})
.then(
() => {
res.status(200).json({
message: 'User profile successfully updated.'
});
console.log('hello there!');
})
.catch(
err => {
return res.status(400).end({
message: err
});
}
);
}

Continue reading...
 
Top