diff --git a/index.js b/index.js index 5f0a4ca..177c393 100644 --- a/index.js +++ b/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]); - } - - res.send(`

ID: ${id}
Название: ${title}
Дата: ${date}
Описание: ${description}

`); + 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('

404 Not found

'); + } + } + ); }); -// UPDATE `blog`.`posts` SET `description` = 'gfhj' WHERE (`id` = '10'); // 404 redirect error app.use((req, res) => { diff --git a/public/css/style.css b/public/css/style.css index a02d904..1f8893a 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -57,4 +57,15 @@ 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; } \ No newline at end of file diff --git a/public/js/script.js b/public/js/script.js index 67f22ef..d57d33d 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -16,10 +16,10 @@ function updatePost() { btnSend.addEventListener('click', (e) => { let idInputValue = idInput.value; - + if (!isNaN(idInputValue) == false) { alert('Поле ID должен быть числом!'); - e.preventDefault(); + e.preventDefault(); } else { idInputValue = idInputValue.trim(); } diff --git a/views/main.pug b/views/main.pug index 0a5c129..3f092e7 100644 --- a/views/main.pug +++ b/views/main.pug @@ -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 \ No newline at end of file