diff --git a/public/js/map.js b/public/js/map.js index e17f7f1..226748c 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -3,12 +3,11 @@ import { initEvents } from "./eventHandler.js"; import { mapInit } from "./mapInit.js"; let editMode = false; -const lastUpdateCheck = new Date().getTime(); +let lastUpdateCheck = Date.now(); const map = mapInit(); - -initEvents(map); +initEvents(map); async function fetchAllMarkers() { const response = await fetch("/fetchMarkers"); @@ -20,7 +19,6 @@ async function fetchAllMarkers() { }); } - export async function fetchNewMarkers() { const searchParams = new URLSearchParams({ fromDate: lastUpdateCheck }); @@ -32,15 +30,17 @@ export async function fetchNewMarkers() { createMarker(marker, L, map); }); - lastUpdateCheck = new Date().getTime(); + lastUpdateCheck = Date.now(); } const main = async () => { - await fetchAllMarkers(); - - setInterval(fetchNewMarkers, 5000); -} + await fetchAllMarkers(); -main().then(() => { - console.log("Completed") -}).catch(console.error) \ No newline at end of file + setInterval(fetchNewMarkers, 5000); +}; + +main() + .then(() => { + console.log("Completed"); + }) + .catch(console.error); diff --git a/server/dbHandler.js b/server/dbHandler.js index 2a44f95..1d40153 100644 --- a/server/dbHandler.js +++ b/server/dbHandler.js @@ -51,6 +51,8 @@ function getUpdatedMarkers(fromDate, callback) { connection.release(); // return the connection to pool if (err) throw err; callback(rows); + + console.log(rows) }); }); } diff --git a/server/index.js b/server/index.js index bb0af77..ff00e25 100644 --- a/server/index.js +++ b/server/index.js @@ -13,11 +13,11 @@ const configureRoutes = (app) => { app.get("/", (req, res) => { res.sendFile(`${PUBLIC_PATH}/index.html`); }); - + app.post("/uploadMarker", upload.single("image"), (req, res) => { const data = req.body; image = req.file; - + // Extract marker data const newMarker = { name: data.name, @@ -29,22 +29,24 @@ const configureRoutes = (app) => { // Add marker to db dbHandler.addMarker(newMarker); }); - + app.get("/fetchMarkers", (req, res) => { dbHandler.getAllMarkers((rows) => { res.status(200).json(rows); }); }); - + app.get("/updateMarkers", (req, res) => { const data = req.query; - //console.log(data.fromDate) - dbHandler.getUpdatedMarkers(data.fromDate, (rows) => { + + console.log(data.fromDate) + console.log() + + dbHandler.getUpdatedMarkers(new Date(Number(data.fromDate)), (rows) => { res.status(200).json(rows); }); }); - -} +}; const configureExpress = () => { const app = express(); @@ -54,27 +56,30 @@ const configureExpress = () => { app.use("/imgs", express.static(config.get("app.upload"))); app.use(express.json()); // for json app.use( - express.urlencoded({ extended: true, limit: "12MB", parameterLimit: 100000 }) + express.urlencoded({ + extended: true, + limit: "12MB", + parameterLimit: 100000, + }) ); // support encoded bodies - configureRoutes(app) - - server = app.listen(port, () => { + configureRoutes(app); + + server = app.listen(port, "0.0.0.0", () => { console.log(`Example app listening on port ${port}`); }); return app; -} - +}; const main = () => { - process.on('SIGINT', () => { + process.on("SIGINT", () => { server.close(() => { - console.log('Successfully closed HTTP Server.'); + console.log("Successfully closed HTTP Server."); }); }); - configureExpress() -} + configureExpress(); +}; -main(); \ No newline at end of file +main();