mirror of
https://github.com/sergeyyarkov/blog-expressjs.git
synced 2026-10-11 10:19:07 +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) => {
|
app.post('/update', (req, res) => {
|
||||||
const id = req.body.id,
|
|
||||||
title = req.body.title,
|
|
||||||
date = req.body.date,
|
|
||||||
description = req.body.description;
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
id: req.body.id,
|
id: req.body.id,
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
date: req.body.date,
|
date: req.body.date,
|
||||||
description: req.body.description
|
description: req.body.description
|
||||||
};
|
};
|
||||||
|
conn.query(
|
||||||
for (let k in data) {
|
`UPDATE posts SET title='${data.title}', date='${data.date}', description='${data.description}' WHERE id=${data.id}`,
|
||||||
console.log(k + ' : ' + data[k]);
|
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
|
// 404 redirect error
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
|
|||||||
@ -58,3 +58,14 @@ input[type="date"] {
|
|||||||
.modal {
|
.modal {
|
||||||
min-width: 500px;
|
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 Все записи:
|
h1 Все записи:
|
||||||
include assets/update-form.pug
|
include assets/update-form.pug
|
||||||
include assets/post-card.pug
|
include assets/post-card.pug
|
||||||
|
div(class="post-block_add")
|
||||||
|
h3 Добавить запись
|
||||||
include assets/scripts.pug
|
include assets/scripts.pug
|
||||||
Loading…
x
Reference in New Issue
Block a user