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,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)
setInterval(fetchNewMarkers, 5000);
};
main()
.then(() => {
console.log("Completed");
})
.catch(console.error);

View file

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

View file

@ -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();
main();