From 38aa006eccab9341afa3aa3640a0c18981ec8dcc Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Sun, 16 Sep 2018 03:11:21 -0300 Subject: [PATCH] Add device_id to cash_out_actions table (#164) If a costumer originates a cashOut transaction at one device, and then redeemed at a different device, the wrong machine would have bills debited from it. With device_id being saved at the cash_out_actions table the bills can be properly reconciled. --- lib/cash-out/cash-out-actions.js | 2 +- ...536651947391-add-device-id-to-cash-out-actions.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 migrations/1536651947391-add-device-id-to-cash-out-actions.js diff --git a/lib/cash-out/cash-out-actions.js b/lib/cash-out/cash-out-actions.js index f63b3296..420e0ae9 100644 --- a/lib/cash-out/cash-out-actions.js +++ b/lib/cash-out/cash-out-actions.js @@ -18,7 +18,7 @@ function logActionById (t, action, _rec, txId) { } function logAction (t, action, _rec, tx) { - const rec = _.assign(_rec, {action, tx_id: tx.id, redeem: !!tx.redeem}) + const rec = _.assign(_rec, {action, tx_id: tx.id, redeem: !!tx.redeem, device_id: tx.deviceId}) const sql = pgp.helpers.insert(rec, null, 'cash_out_actions') return t.none(sql) diff --git a/migrations/1536651947391-add-device-id-to-cash-out-actions.js b/migrations/1536651947391-add-device-id-to-cash-out-actions.js new file mode 100644 index 00000000..3a07a6bf --- /dev/null +++ b/migrations/1536651947391-add-device-id-to-cash-out-actions.js @@ -0,0 +1,12 @@ +var db = require('./db') + +exports.up = function (next) { + var sql = [ + "alter table cash_out_actions add device_id text not null default ''" + ] + db.multi(sql, next) +} + +exports.down = function (next) { + next() +}