mirror of
https://github.com/sergeyyarkov/blog-expressjs.git
synced 2026-10-12 02:39:01 +03:00
added update post
This commit is contained in:
parent
184c03aeaf
commit
d0f3f49db0
20
index.js
20
index.js
@ -73,25 +73,23 @@ app.get('/delete/:id', (req, res) => {
|
||||
|
||||
// запрос на редактирование
|
||||
app.post('/update', (req, res) => {
|
||||
const id = req.body.id,
|
||||
title = req.body.title,
|
||||
date = req.body.date,
|
||||
description = req.body.description;
|
||||
|
||||
const data = {
|
||||
id: req.body.id,
|
||||
title: req.body.title,
|
||||
date: req.body.date,
|
||||
description: req.body.description
|
||||
};
|
||||
|
||||
for (let k in data) {
|
||||
console.log(k + ' : ' + data[k]);
|
||||
conn.query(
|
||||
`UPDATE posts SET title='${data.title}', date='${data.date}', description='${data.description}' WHERE id=${data.id}`,
|
||||
function(err, result) {
|
||||
if (!err) {
|
||||
res.send('Пост был успешно отредактирован');
|
||||
} else {
|
||||
res.status(404).send('<h1>404 Not found</h1>');
|
||||
}
|
||||
|
||||
res.send(`<p>ID: ${id}<br>Название: ${title}<br>Дата: ${date}<br>Описание: ${description}</p>`);
|
||||
}
|
||||
);
|
||||
});
|
||||
// UPDATE `blog`.`posts` SET `description` = 'gfhj' WHERE (`id` = '10');
|
||||
|
||||
// 404 redirect error
|
||||
app.use((req, res) => {
|
||||
|
||||
@ -58,3 +58,14 @@ input[type="date"] {
|
||||
.modal {
|
||||
min-width: 500px;
|
||||
}
|
||||
.post-block_add {
|
||||
border: 6px dashed;
|
||||
text-align: center;
|
||||
padding: 70px 0px 70px 0px;
|
||||
cursor: pointer;
|
||||
transition: all .2s;
|
||||
margin-top: 3rem;
|
||||
}
|
||||
.post-block_add:hover {
|
||||
opacity: .9;
|
||||
}
|
||||
@ -4,4 +4,6 @@ div(class="container")
|
||||
h1 Все записи:
|
||||
include assets/update-form.pug
|
||||
include assets/post-card.pug
|
||||
div(class="post-block_add")
|
||||
h3 Добавить запись
|
||||
include assets/scripts.pug
|
||||
Loading…
x
Reference in New Issue
Block a user