Created
May 15, 2013 12:26
-
-
Save Hogent/5583643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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