diff --git a/lib/logs.js b/lib/logs.js index 336b0ca2..278f8b30 100644 --- a/lib/logs.js +++ b/lib/logs.js @@ -18,11 +18,11 @@ const NUM_RESULTS = 1000 * @returns {date} Last timestamp */ function getLastSeen (deviceId) { - const sql = `select timestamp from logs + const sql = `select id, timestamp from logs where device_id=$1 order by timestamp desc limit 1` return db.oneOrNone(sql, [deviceId]) - .then(log => log ? log.timestamp : null) + .then(log => log ? {timestamp: log.timestamp, id: log.id} : null) } /** diff --git a/lib/routes.js b/lib/routes.js index 17589a3a..940df7a3 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -177,7 +177,7 @@ function getCustomerWithPhoneCode (req, res, next) { function getLastSeen (req, res, next) { return logs.getLastSeen(req.deviceId) - .then(timestamp => res.json({lastSeen: timestamp})) + .then(r => res.json(r)) .catch(next) } @@ -266,7 +266,9 @@ function authorize (req, res, next) { .catch(next) } -const skip = (req, res) => _.includes(req.path, ['/poll', '/state']) && res.statusCode === 200 +const skip = (req, res) => _.includes(req.path, ['/poll', '/state', '/logs']) && + res.statusCode === 200 && + req.method === 'GET' const configRequiredRoutes = [ '/poll',