From c6b92f06e0e9740e60ada87d29a6689fd6f1002e Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 22 Sep 2023 22:47:53 +0300 Subject: [PATCH] devices deletion and fix bugs --- server.js | 27 +++++++++++ static/scripts/table.js | 1 + static/styles/main.css | 1 + static/templates/admin/index.html | 2 +- static/templates/devices/drivers.html | 2 +- static/templates/devices/index.html | 66 +++++++++++++++++++++++++-- static/templates/reports/index.html | 2 +- 7 files changed, 95 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index fc159f4..0d83d8b 100644 --- a/server.js +++ b/server.js @@ -2592,6 +2592,33 @@ app.post("/deletedriver", async (req, res) => { } }); +app.post("/deletedevice", async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + const id = req.body.id; + + const pool = new Pool({ + user: DB_User, + host: DB_Host, + database: DB_Name, + password: DB_Password, + port: DB_Port, + }); + const client = await pool.connect(); + + try { + // Выполняем запрос и получаем результат + const query = "DELETE FROM registrars WHERE id = $1;"; + const devicedata = await client.query(query, [id]); + + // Формирование и отправка ответа + res.send("Data deleted successfully"); + } finally { + client.release(); + } +}); + app.post("/deleteuser", async (req, res) => { if (req.session.userId === undefined) { return res.redirect("/signin"); diff --git a/static/scripts/table.js b/static/scripts/table.js index 25a14ec..f020039 100644 --- a/static/scripts/table.js +++ b/static/scripts/table.js @@ -83,6 +83,7 @@ const createTable = () => { trashButton.setAttribute("class", "trash"); trashButton.value = `delete-device-${device.id}`; trashButton.id = `delete-device-${device.id}`; + trashButton.setAttribute("onclick", `deleteDevice(${device.id})`); trashCell.appendChild(trashButton); } if (EditTransport) { diff --git a/static/styles/main.css b/static/styles/main.css index d4fc598..4e03600 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -684,6 +684,7 @@ header img { border: 2px solid rgba(245, 245, 250, 1); border-radius: 30px; overflow: hidden; + overflow-x: auto; position: relative; } diff --git a/static/templates/admin/index.html b/static/templates/admin/index.html index 9c7999b..c7eba6f 100644 --- a/static/templates/admin/index.html +++ b/static/templates/admin/index.html @@ -175,7 +175,7 @@

Удаление водителя


Вы уверены что хотите удалить ?
- +
diff --git a/static/templates/devices/drivers.html b/static/templates/devices/drivers.html index 5eb2918..f689e50 100644 --- a/static/templates/devices/drivers.html +++ b/static/templates/devices/drivers.html @@ -126,7 +126,7 @@ Номер телефона Почта Карта водителя - + diff --git a/static/templates/devices/index.html b/static/templates/devices/index.html index 1a8aaeb..b34045b 100644 --- a/static/templates/devices/index.html +++ b/static/templates/devices/index.html @@ -130,9 +130,7 @@ Статус Номер SIM-карты IP-адрес - {{#if DeleteTransport}} - - {{/if}} + @@ -657,6 +655,18 @@ + + + +