From 272127518df83771ff87ca2ba309d5d42ae24b57 Mon Sep 17 00:00:00 2001 From: Zoran Joka Date: Sun, 4 Nov 2018 19:14:27 +0100 Subject: [PATCH] Update last_online device field on each machine ping (#203) * update last_online device field on each machine ping * change var name to camel-case * Use pgp name parameters instead of interpolation --- lib/plugins.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index 6cb90db2..9a297a46 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -231,14 +231,20 @@ function plugins (settings, deviceId) { } function recordPing (serialNumber, deviceTime, rec) { - const r = { + const machinePings = { id: uuid.v4(), device_id: deviceId, serial_number: serialNumber, device_time: deviceTime } + const devices = { + last_online: deviceTime + } - return db.none(pgp.helpers.insert(r, null, 'machine_pings')) + return Promise.all([ + db.none(pgp.helpers.insert(machinePings, null, 'machine_pings')), + db.none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', { deviceId }) + ]) } function isHd (tx) {