Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.put("/api/students/:studentId", function(req, res) {
- var updateDoc = req.body;
- delete updateDoc._id;
- db.collection(STUDENTS_COLLECTION).findOne({
- studentId: parseInt(req.params.studentId)
- }, function(err, doc) {
- if (err) {
- handleError(res, err.message, "No student with id " + req.params.studentId);
- } else {
- if (doc) {
- updateDoc.studentId = doc.studentId
- db.collection(STUDENTS_COLLECTION).updateOne({
- studentId: doc.studentId
- }, updateDoc, function(err, finalDoc) {
- if (err) {
- handleError(res, err.message, "Failed to update student");
- } else {
- res.status(200).json(finalDoc);
- }
- });
- } else {
- handleError(res, "Invalid user input", "No student with id " + req.params.studentId);
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement