Fix date hell

This commit is contained in:
0d0acre 2024-09-21 01:31:23 +02:00
parent 7c7092d125
commit a5ba2d2413
3 changed files with 38 additions and 31 deletions

View file

@ -3,13 +3,12 @@ import { initEvents } from "./eventHandler.js";
import { mapInit } from "./mapInit.js"; import { mapInit } from "./mapInit.js";
let editMode = false; let editMode = false;
const lastUpdateCheck = new Date().getTime(); let lastUpdateCheck = Date.now();
const map = mapInit(); const map = mapInit();
initEvents(map); initEvents(map);
async function fetchAllMarkers() { async function fetchAllMarkers() {
const response = await fetch("/fetchMarkers"); const response = await fetch("/fetchMarkers");
@ -20,7 +19,6 @@ async function fetchAllMarkers() {
}); });
} }
export async function fetchNewMarkers() { export async function fetchNewMarkers() {
const searchParams = new URLSearchParams({ fromDate: lastUpdateCheck }); const searchParams = new URLSearchParams({ fromDate: lastUpdateCheck });
@ -32,15 +30,17 @@ export async function fetchNewMarkers() {
createMarker(marker, L, map); createMarker(marker, L, map);
}); });
lastUpdateCheck = new Date().getTime(); lastUpdateCheck = Date.now();
} }
const main = async () => { const main = async () => {
await fetchAllMarkers(); await fetchAllMarkers();
setInterval(fetchNewMarkers, 5000); setInterval(fetchNewMarkers, 5000);
} };
main().then(() => { main()
console.log("Completed") .then(() => {
}).catch(console.error) console.log("Completed");
})
.catch(console.error);

View file

@ -51,6 +51,8 @@ function getUpdatedMarkers(fromDate, callback) {
connection.release(); // return the connection to pool connection.release(); // return the connection to pool
if (err) throw err; if (err) throw err;
callback(rows); callback(rows);
console.log(rows)
}); });
}); });
} }

View file

@ -38,13 +38,15 @@ const configureRoutes = (app) => {
app.get("/updateMarkers", (req, res) => { app.get("/updateMarkers", (req, res) => {
const data = req.query; 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); res.status(200).json(rows);
}); });
}); });
};
}
const configureExpress = () => { const configureExpress = () => {
const app = express(); const app = express();
@ -54,27 +56,30 @@ const configureExpress = () => {
app.use("/imgs", express.static(config.get("app.upload"))); app.use("/imgs", express.static(config.get("app.upload")));
app.use(express.json()); // for json app.use(express.json()); // for json
app.use( app.use(
express.urlencoded({ extended: true, limit: "12MB", parameterLimit: 100000 }) express.urlencoded({
extended: true,
limit: "12MB",
parameterLimit: 100000,
})
); // support encoded bodies ); // support encoded bodies
configureRoutes(app) configureRoutes(app);
server = app.listen(port, () => { server = app.listen(port, "0.0.0.0", () => {
console.log(`Example app listening on port ${port}`); console.log(`Example app listening on port ${port}`);
}); });
return app; return app;
} };
const main = () => { const main = () => {
process.on('SIGINT', () => { process.on("SIGINT", () => {
server.close(() => { server.close(() => {
console.log('Successfully closed HTTP Server.'); console.log("Successfully closed HTTP Server.");
}); });
}); });
configureExpress() configureExpress();
} };
main(); main();