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