Fix date hell
This commit is contained in:
parent
7c7092d125
commit
a5ba2d2413
3 changed files with 38 additions and 31 deletions
|
@ -3,12 +3,11 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
main().then(() => {
|
setInterval(fetchNewMarkers, 5000);
|
||||||
console.log("Completed")
|
};
|
||||||
}).catch(console.error)
|
|
||||||
|
main()
|
||||||
|
.then(() => {
|
||||||
|
console.log("Completed");
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
|
@ -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)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ const configureRoutes = (app) => {
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.sendFile(`${PUBLIC_PATH}/index.html`);
|
res.sendFile(`${PUBLIC_PATH}/index.html`);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/uploadMarker", upload.single("image"), (req, res) => {
|
app.post("/uploadMarker", upload.single("image"), (req, res) => {
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
image = req.file;
|
image = req.file;
|
||||||
|
|
||||||
// Extract marker data
|
// Extract marker data
|
||||||
const newMarker = {
|
const newMarker = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
@ -29,22 +29,24 @@ const configureRoutes = (app) => {
|
||||||
// Add marker to db
|
// Add marker to db
|
||||||
dbHandler.addMarker(newMarker);
|
dbHandler.addMarker(newMarker);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/fetchMarkers", (req, res) => {
|
app.get("/fetchMarkers", (req, res) => {
|
||||||
dbHandler.getAllMarkers((rows) => {
|
dbHandler.getAllMarkers((rows) => {
|
||||||
res.status(200).json(rows);
|
res.status(200).json(rows);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
|
|
Loading…
Reference in a new issue