From a5584107963ba976b7a7e3f5dccb2cc41d60f81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 4 Apr 2022 16:35:44 +0100 Subject: [PATCH] fix: only change customerId in presence of an anonymous customer --- lib/cash-out/cash-out-low.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cash-out/cash-out-low.js b/lib/cash-out/cash-out-low.js index 2772374f..91130119 100644 --- a/lib/cash-out/cash-out-low.js +++ b/lib/cash-out/cash-out-low.js @@ -2,6 +2,7 @@ const _ = require('lodash/fp') const pgp = require('pg-promise')() const helper = require('./cash-out-helper') +const { anonymousCustomer } = require('../constants') const toDb = helper.toDb const toObj = helper.toObj @@ -52,7 +53,15 @@ function diff (oldTx, newTx) { // We never null out an existing field if (oldTx && _.isNil(newTx[fieldKey])) return - updatedTx[fieldKey] = newTx[fieldKey] + switch (fieldKey) { + case 'customerId': + if (oldTx.customerId === anonymousCustomer.uuid) { + return updatedTx['customerId'] = newTx['customerId'] + } + return + default: + return updatedTx[fieldKey] = newTx[fieldKey] + } }) return updatedTx