a few changes to position history feature
This commit is contained in:
21
src/index.js
21
src/index.js
@ -431,10 +431,16 @@ app.get('/api/v1/nodes/:nodeId/traceroutes', async (req, res) => {
|
||||
app.get('/api/v1/nodes/:nodeId/position-history', async (req, res) => {
|
||||
try {
|
||||
|
||||
const nodeId = parseInt(req.params.nodeId);
|
||||
const timeFrom = req.query.time_from ? parseInt(req.query.time_from) : new Date().getTime() - 3600 * 1000;
|
||||
const timeTo = req.query.time_to ? parseInt(req.query.time_to) : new Date().getTime();
|
||||
// defaults
|
||||
const nowInMilliseconds = new Date().getTime();
|
||||
const oneHourAgoInMilliseconds = new Date().getTime() - (3600 * 1000);
|
||||
|
||||
// get request params
|
||||
const nodeId = parseInt(req.params.nodeId);
|
||||
const timeFrom = req.query.time_from ? parseInt(req.query.time_from) : oneHourAgoInMilliseconds;
|
||||
const timeTo = req.query.time_to ? parseInt(req.query.time_to) : nowInMilliseconds;
|
||||
|
||||
// find node
|
||||
const node = await prisma.node.findFirst({
|
||||
where: {
|
||||
node_id: nodeId,
|
||||
@ -477,8 +483,7 @@ app.get('/api/v1/nodes/:nodeId/position-history', async (req, res) => {
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
altitude: position.altitude,
|
||||
accuracy: position.accuracy,
|
||||
time: position.created_at,
|
||||
created_at: position.created_at,
|
||||
});
|
||||
});
|
||||
|
||||
@ -488,12 +493,12 @@ app.get('/api/v1/nodes/:nodeId/position-history', async (req, res) => {
|
||||
latitude: mapReport.latitude,
|
||||
longitude: mapReport.longitude,
|
||||
altitude: mapReport.altitude,
|
||||
accuracy: mapReport.accuracy,
|
||||
time: mapReport.created_at,
|
||||
created_at: mapReport.created_at,
|
||||
});
|
||||
});
|
||||
|
||||
positionHistory.sort((a, b) => a.time - b.time);
|
||||
// sort oldest to newest
|
||||
positionHistory.sort((a, b) => a.created_at - b.created_at);
|
||||
|
||||
res.json({
|
||||
position_history: positionHistory,
|
||||
|
Reference in New Issue
Block a user