Skip to content
Snippets Groups Projects
Commit 6fdead9a authored by Herman Ryen Martinsen's avatar Herman Ryen Martinsen
Browse files

La til metode for å oppdatere en person

parent 83a60dc1
No related branches found
No related tags found
No related merge requests found
Pipeline #22853 passed
...@@ -22,12 +22,20 @@ module.exports = class PersonDao extends Dao { ...@@ -22,12 +22,20 @@ module.exports = class PersonDao extends Dao {
); );
} }
updateOne(json, callback) { updateOne(id, json, callback) {
var val = [json.navn, json.adresse, json.alder, json.id]; var val = [json.navn, json.adresse, json.alder, id];
super.query( super.query(
"update person set navn=?, adresse=?, alder=?, where id=?", "update person set navn=?, adresse=?, alder=? where id=?",
val, val,
callback callback
); );
} }
};
deleteOne(id, callback) {
super.query(
"delete from person where id=?",
[id],
callback
);
}
};
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"express": "^4.16.3", "express": "^4.16.3",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"jest": "^23.6.0", "jest": "^23.6.0",
"jest-cli": "^23.6.0",
"mysql": "^2.16.0" "mysql": "^2.16.0"
}, },
"scripts": { "scripts": {
......
...@@ -41,4 +41,20 @@ app.post("/person", (req, res) => { ...@@ -41,4 +41,20 @@ app.post("/person", (req, res) => {
}); });
}); });
app.put("/person/:personId", (req, res) => {
console.log("Fikk PUT-request fra klienten");
personDao.updateOne(req.params.personId, req.body, (status, data) => {
res.status(status);
res.json(data);
});
});
app.delete("/person/:personId", (req, res) => {
console.log("Fikk DELETE-request fra klienten");
personDao.deleteOne(req.params.personId, (status, data) => {
res.status(status);
res.json(data);
});
});
var server = app.listen(8080); var server = app.listen(8080);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment