Skip to content

Instantly share code, notes, and snippets.

@Hogent
Created May 15, 2013 12:26
Show Gist options
  • Save Hogent/5583643 to your computer and use it in GitHub Desktop.
Save Hogent/5583643 to your computer and use it in GitHub Desktop.
// routes/notes.js
...
exports.updateNote = function(req, res) {
var id = req.params.id;
Note.findById(id, function (err, doc){
if(!err) {
doc.title = req.body.title;
doc.note = req.body.note;
doc.save(function(err, result) {
if (err){
res.send({'error':'An error has occurred'});
}
else {
res.send(result);
}
});
}
else{
var note = new Note();
note.title = req.body.title;
note.note = req.body.note;
note.save(function (err, doc) {
if (err) {
res.send({'error':'An error has occurred'});
}
else{
res.send(doc);
}
});
}
});
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment