From 09332c37db1f7a220d32f7ccc0dbcb92461de404 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 27 May 2019 22:47:01 -0300 Subject: [PATCH] Delete machine pings on unpair --- lib/notifier.js | 2 ++ lib/pairing.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/notifier.js b/lib/notifier.js index afad9582..0885fd12 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -229,6 +229,8 @@ function alertSubject (alertRec) { alerts = _.concat(alerts, alertRec.devices[device]) }) + if (alerts.length === 0) return null + const alertTypes = _.map(codeDisplay, _.uniq(_.map('code', alerts))).sort() return '[Lamassu] Errors reported: ' + alertTypes.join(', ') } diff --git a/lib/pairing.js b/lib/pairing.js index 6fc8599d..180aae6b 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -37,7 +37,8 @@ function removeDeviceConfig (deviceId) { function unpair (deviceId) { const sql = 'delete from devices where device_id=$1' - return db.none(sql, [deviceId]) + const deleteMachinePings = 'delete from machine_pings where device_id=$1' + return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId])]) .then(() => removeDeviceConfig(deviceId)) }