From e0492512f5745e28b11406a591c1928787b77845 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Fri, 5 Apr 2024 15:00:15 +1300 Subject: [PATCH] if a new waypoint is received that expires an existing waypoint, it should expire it --- src/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index f7b61ce..6a3ac3e 100644 --- a/src/index.js +++ b/src/index.js @@ -279,13 +279,8 @@ app.get('/api/v1/stats/hardware-models', async (req, res) => { app.get('/api/v1/waypoints', async (req, res) => { try { - // get waypoints from db that have not expired yet + // get waypoints from db const waypoints = await prisma.waypoint.findMany({ - where: { - expire: { - gte: Math.floor(Date.now() / 1000), // now in seconds - }, - }, orderBy: { id: 'desc', }, @@ -306,8 +301,14 @@ app.get('/api/v1/waypoints', async (req, res) => { } + // we only want waypoints that haven't expired yet + const nonExpiredWayPoints = uniqueWaypoints.filter((waypoint) => { + const nowInSeconds = Math.floor(Date.now() / 1000); + return waypoint.expire >= nowInSeconds; + }); + res.json({ - waypoints: uniqueWaypoints, + waypoints: nonExpiredWayPoints, }); } catch(err) {