diff --git a/data.db b/data.db index af72f0b..24a6209 100644 --- a/data.db +++ b/data.db @@ -1,4 +1,3 @@ {"name":"three","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"a84IEbquFHLCK8Zj"} -{"name":"two","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"kY56cQascxWJyh7A"} +{"name":"two","weight":"60","height":"20","hairColour":"black","gpa":"3","_id":"kY56cQascxWJyh7A"} {"name":"four","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"wIVpbISz0AOSrmmy"} -{"name":"five","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"6hjW9b8MA1SIqYUT"} diff --git a/index.js b/index.js index d23ea1a..b1624e5 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,8 @@ app.post('/student', (req, res) => { res.status(500).json(err); } console.log("new student added", newStudent); - res.json(newStudent); + //res.json(newStudent); + database.persistence.compactDatafile() }); }); @@ -37,10 +38,20 @@ app.delete('/student', (req, res) => { res.status(500).json(err); } console.log("student removed", newStudent); - // database.persistence.compactDatafile() - return res.send("Stdent has been removed"); + database.persistence.compactDatafile() + //return res.send("Stdent has been removed"); }); // database.persistence.compactDatafile() - res.send("Seems like we don't have anything to delete"); + //res.send("Seems like we don't have anything to delete"); +}); + +app.put('/student', (req, res) => { + database.update({name : req.body.name}, {$set: {weight: req.body.weight, height: req.body.height, hairColour: req.body.hairColour, gpa: req.body.gpa}}, function(err, newStudent){ + if (err){ + res.status(500).json(err); + } + //res.json(newStudent); + database.persistence.compactDatafile() + }); }); diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..cc84677 --- /dev/null +++ b/public/index.html @@ -0,0 +1,23 @@ + +
+ + + + + + + + +