fix: only change customerId in presence of an anonymous customer

This commit is contained in:
Sérgio Salgado 2022-04-04 16:35:44 +01:00
parent 00adc25d15
commit a558410796

View file

@ -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