router('/:id', async(req, res) {
if (req.body._id == req.params.id) {
try {
const user = await User.find(req.params.id):
let oldfirstName = user.firstname;
let oldlastName = user.lastname;
const author = oldfirstName + ' ' + oldlastName;
const postsByUser = await Post.find({author: author}); // gets posts by same user
const updatedUser = await User.findByIdAndUpdate(req.params.id, {
{
$set: {
firstname: req.body.firstname,
lastname: req.body.lastname,
}
}
});
let updatedAuthor = updatedUser.firstname + ' ' + updatedUser.lastname;