From 89019f168c6155b4d3243a53120358bdcc15fb39 Mon Sep 17 00:00:00 2001 From: scossa Date: Sat, 7 Sep 2024 01:41:43 +0200 Subject: [PATCH] cena a casa di cek --- dbHandler.js | 11 ++++++++--- initDb.sql | 2 +- script/AggiornaRuscoMap.sh | 0 script/cerca_rusco.sh | 0 script/delete_rusco.sh | 0 utils.js | 0 6 files changed, 9 insertions(+), 4 deletions(-) mode change 100644 => 100755 script/AggiornaRuscoMap.sh mode change 100644 => 100755 script/cerca_rusco.sh mode change 100644 => 100755 script/delete_rusco.sh create mode 100644 utils.js diff --git a/dbHandler.js b/dbHandler.js index 97f9fa1..414f85a 100644 --- a/dbHandler.js +++ b/dbHandler.js @@ -1,6 +1,7 @@ const config = require('config'); const mysql = require('mysql'); - +const dateToUtc = require('./utils.js') + const pool = mysql.createPool({ host: config.get('db.host'), user: config.get('db.user'), @@ -10,7 +11,11 @@ const pool = mysql.createPool({ function addMarker(marker) { let insertQuery = 'INSERT INTO markers VALUES (?,?,?,POINT(?,?),?)'; - let query = mysql.format(insertQuery, [marker.name, marker.description, marker.filename, marker.long, marker.lat, new Date()]); + const date = new Date().toISOString() + const datePart = date.slice(0, 10); // '2024-09-06' + const timePart = date.slice(11, 19); // '21:33:44' + const formattedDate = `${datePart} ${timePart}` + let query = mysql.format(insertQuery, [marker.name, marker.dTIMESTAMPescription, marker.filename, marker.long, marker.lat, formattedDate]); pool.query(query, (err, response) => { if (err) { console.error(err); @@ -36,7 +41,7 @@ function getUpdatedMarkers(fromDate, callback) { pool.getConnection((err, connection) => { if (err) throw err; let selectQuery = 'SELECT * FROM markers mrk WHERE mrk.ts >= ?'; - let query = mysql.format(selectQuery, [new Date(parseInt(fromDate))]) + let query = mysql.format(selectQuery, fromDate) connection.query(query, (err, rows) => { connection.release(); // return the connection to pool if (err) throw err; diff --git a/initDb.sql b/initDb.sql index b9023aa..1f55cb7 100644 --- a/initDb.sql +++ b/initDb.sql @@ -8,5 +8,5 @@ CREATE TABLE ruscomap.markers ( description VARCHAR(1024), filename VARCHAR(256) NOT NULL, coordinate POINT NOT NULL, - ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP2 ); \ No newline at end of file diff --git a/script/AggiornaRuscoMap.sh b/script/AggiornaRuscoMap.sh old mode 100644 new mode 100755 diff --git a/script/cerca_rusco.sh b/script/cerca_rusco.sh old mode 100644 new mode 100755 diff --git a/script/delete_rusco.sh b/script/delete_rusco.sh old mode 100644 new mode 100755 diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..e69de29