From 3f46614ff569bc348b3776f6a7096fd84733c706 Mon Sep 17 00:00:00 2001 From: Taranto Date: Sun, 9 Jul 2023 21:15:33 +0100 Subject: [PATCH] chore: comments and better error message --- lib/cash-out/cash-out-atomic.js | 6 ++---- lib/cash-out/cash-out-low.js | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/cash-out/cash-out-atomic.js b/lib/cash-out/cash-out-atomic.js index 29220677..9c5fe85b 100644 --- a/lib/cash-out/cash-out-atomic.js +++ b/lib/cash-out/cash-out-atomic.js @@ -27,11 +27,9 @@ function atomic (tx, pi, fromClient) { const isStale = fromClient && oldTx && (oldTx.txVersion >= tx.txVersion) if (isStale) throw new E.StaleTxError({ txId: tx.id }) + // Server doesn't bump version, so we just prevent from version being older. const isStaleFromServer = !fromClient && oldTx && (oldTx.txVersion > tx.txVersion) - if (isStaleFromServer) { - logger.info('trying to update older version of tx', JSON.stringify(tx)) - return Promise.resolve() - } + if (isStaleFromServer) throw new Error('Stale Error: server triggered', tx.id) return preProcess(t, oldTx, tx, pi) .then(preProcessedTx => cashOutLow.upsert(t, oldTx, preProcessedTx)) diff --git a/lib/cash-out/cash-out-low.js b/lib/cash-out/cash-out-low.js index 7431334e..24aea40c 100644 --- a/lib/cash-out/cash-out-low.js +++ b/lib/cash-out/cash-out-low.js @@ -59,6 +59,7 @@ function diff (oldTx, newTx) { return updatedTx['customerId'] = newTx['customerId'] } return + // prevent dispense changing from 'true' to 'false' case 'dispense': if (!oldTx.dispense) { return updatedTx[fieldKey] = newTx[fieldKey]