This commit is contained in:
j.mei7
2022-04-03 16:38:57 +02:00
parent c2670a09aa
commit eddfa544a4
7 changed files with 478 additions and 32 deletions

View File

@@ -5,6 +5,12 @@ const sqlite3 = require('sqlite3');
const db = new sqlite3.Database("database.db")
const port = process.env.PORT || 5000;
// body parser
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods","POST","GET")
@@ -39,4 +45,15 @@ app.get('/ideas', (req, res) => {
res.json(rows);
}
});
});
app.post('/idea/update/:id', (req, res) => {
db.run(`UPDATE ideas SET title = '${req.body.title}', content = '${req.body.content}' WHERE id = ${req.params.id}`, (err) => {
if (err) {
res.send({title: "Error", content: "Error updating idea"});
}else{
res.send({title: "Success", content: "Idea updated"});
}
});
});