code complete

pull/1/head
Matt Huntington 5 years ago
parent 2651dfe858
commit 6a2127a7bb

@ -9,26 +9,27 @@ router.get('/', (req, res) => {
});
router.post('/', (req, res) => {
data.push(req.body);
res.json(data);
postgres.query(`INSERT INTO people (name, age) VALUES ('${req.body.name}', ${req.body.age})`, (err, results) => {
postgres.query('SELECT * FROM people ORDER BY id ASC;', (err, results) => {
res.json(results.rows)
});
})
});
router.delete('/:id', (req, res) => {
data = data.filter(person => person.id != req.params.id, 1);
res.json(data);
postgres.query(`DELETE FROM people WHERE id = ${req.params.id};`, (err, results) => {
postgres.query('SELECT * FROM people ORDER BY id ASC;', (err, results) => {
res.json(results.rows)
});
});
});
router.put('/:id', (req, res) => {
req.body.id = req.params.id;
data = data.map((person) => {
if(person.id == req.params.id){
return req.body
} else {
return person
}
postgres.query(`UPDATE people SET name = '${req.body.name}', AGE = ${req.body.age} WHERE id = ${req.params.id}`, (err, results) => {
postgres.query('SELECT * FROM people ORDER BY id ASC;', (err, results) => {
res.json(results.rows)
});
})
res.json(data);
});
module.exports = router;

Loading…
Cancel
Save