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 @@ + + + + + + + +
+ + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/public/script.js b/public/script.js new file mode 100644 index 0000000..76d2048 --- /dev/null +++ b/public/script.js @@ -0,0 +1,24 @@ +window.onload=function(){ + addForm=document.getElementById("add"); + addForm.style.display="none"; +} + + +function addStudent(){ + console.log("add student"); + form=document.getElementById("add"); + form.style.display="block"; +} + +function addData(){ + var name=document.getElementById("addName").value; + var weight=document.getElementById("addWeight").value; + var height=document.getElementById("addHeight").value; + var hairColour=document.getElementById("addHairColour").value; + var gpa=document.getElementById("addGpa").value; + var data={name, weight, height, hairColour, gpa}; + var option={method:"POST", body: JSON.stringify(data), headers:{'Content-Type':'application/json'}}; + console.log(option); + fetch('/student', option); + +} \ No newline at end of file