WIP
This commit is contained in:
parent
408e4b59d5
commit
c38372a173
3 changed files with 19 additions and 29 deletions
|
|
@ -75,25 +75,14 @@ exports.recordBill = function recordBill(deviceFingerprint, rec, cb) {
|
|||
rec.fiat
|
||||
];
|
||||
|
||||
if (rec.partialTx) {
|
||||
values.push(rec.partialTx.satoshis, rec.partialTx.fiat);
|
||||
fields.push('total_satoshis', 'total_fiat');
|
||||
}
|
||||
|
||||
// NOTE: if is here to maintain compatibility with older machines
|
||||
if (rec.uuid) {
|
||||
values.push(rec.uuid);
|
||||
fields.push('uuid');
|
||||
}
|
||||
|
||||
connect(function(err, client, done) {
|
||||
if (err) return cb(err);
|
||||
query(client, getInsertQuery('bills', fields), values, function(err) {
|
||||
done();
|
||||
if (err && PG_ERRORS[err.code] === 'uniqueViolation')
|
||||
return cb(null, {code: 204});
|
||||
|
||||
cb(); // 201 => Accepted / saved
|
||||
// TODO: Handle unique violations more cleanly for idempotency
|
||||
// Now, it just returns an error, which should be fine, but a 204 status
|
||||
// would be nicer.
|
||||
cb(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue