Skip to content

Instantly share code, notes, and snippets.

@gunnigylfa
Created March 2, 2017 18:41
Show Gist options
  • Save gunnigylfa/94426884ffd831d006a9643f1cd2a88b to your computer and use it in GitHub Desktop.
Save gunnigylfa/94426884ffd831d006a9643f1cd2a88b to your computer and use it in GitHub Desktop.
Update a hero in our heroes API
// PUT '/v1/heroes' Update hero entry
api.put('/:id', (req, res) => {
Hero.findById(req.params.id, (err, hero) => {
if (err) {
return res.send(err);
}
hero.name = req.body.name;
hero.secretIdentity = req.body.name;
return hero.save((saveErr, savedHero) => {
if (saveErr) {
return res.send(saveErr);
}
return res.json({
message: 'Hero updated',
hero: savedHero,
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment