start front end

main
mms37 2 years ago
parent 6cbc2d4497
commit c2a6f5a416

@ -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"}

@ -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()
});
});

@ -0,0 +1,23 @@
<!DOCTYPE html>
<head>
<script src="script.js"></script>
</head>
<body>
<button onclick="addStudent()">add student</button>
<form id="add">
<label>name</label>
<input type="text" id="addName"/>
<label>weight</label>
<input type="text" id="addWeight"/>
<label>height</label>
<input type="text" id="addHeight"/>
<label>hair colour</label>
<input type="text" id="addHairColour"/>
<label>gpa</label>
<input type="text" id="addGpa"/>
<button id="submitStudent" onclick="addData()">submit</button>
</form>
</body>
</html>

@ -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);
}
Loading…
Cancel
Save