This commit is contained in:
Josh Harvey 2017-03-06 16:07:00 +02:00
parent 30071151ff
commit 15678530fd
3 changed files with 12 additions and 3 deletions

View file

@ -30,11 +30,22 @@ function post (tx, pi) {
})
}
function nilEqual (a, b) {
if (_.isNil(a) && _.isNil(b)) return true
return undefined
}
function diff (oldTx, newTx) {
let updatedTx = {}
UPDATEABLE_FIELDS.forEach(fieldKey => {
if (oldTx && _.isEqual(oldTx[fieldKey], newTx[fieldKey])) return
console.log('DEBUG80: %j', [oldTx[fieldKey], newTx[fieldKey]])
if (oldTx && _.isEqualWith(nilEqual, oldTx[fieldKey], newTx[fieldKey])) return
// We never null out an existing field
if (oldTx && _.isNil(newTx[fieldKey])) return
updatedTx[fieldKey] = newTx[fieldKey]
})