get all notes from a given ts
This commit is contained in:
parent
76d5e7c7bd
commit
253320ed84
|
@ -524,6 +524,19 @@ ExpressApp.prototype.start = function(opts, cb) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/v1/txnotes/', function(req, res) {
|
||||||
|
getServerWithAuth(req, res, function(server) {
|
||||||
|
var opts = {};
|
||||||
|
if (_.isNumber(+req.query.minTs)) {
|
||||||
|
opts.minTs = +req.query.minTs;
|
||||||
|
}
|
||||||
|
server.getTxNotes(opts, function(err, notes) {
|
||||||
|
if (err) return returnError(err, res, req);
|
||||||
|
res.json(notes);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/v1/fiatrates/:code/', function(req, res) {
|
router.get('/v1/fiatrates/:code/', function(req, res) {
|
||||||
getServerWithAuth(req, res, function(server) {
|
getServerWithAuth(req, res, function(server) {
|
||||||
var opts = {
|
var opts = {
|
||||||
|
|
|
@ -2090,6 +2090,18 @@ WalletService.prototype.getTxNote = function(opts, cb) {
|
||||||
self.storage.fetchTxNote(self.walletId, opts.txid, cb);
|
self.storage.fetchTxNote(self.walletId, opts.txid, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tx notes.
|
||||||
|
* @param {Object} opts
|
||||||
|
* @param {string} opts.minTs[=0] - The start date used to filter notes.
|
||||||
|
*/
|
||||||
|
WalletService.prototype.getTxNotes = function(opts, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
opts = opts || {};
|
||||||
|
self.storage.fetchTxNotes(self.walletId, opts, cb);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeWallet
|
* removeWallet
|
||||||
*
|
*
|
||||||
|
@ -2694,7 +2706,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
self.storage.fetchTxNotes(self.walletId, next);
|
self.storage.fetchTxNotes(self.walletId, {}, next);
|
||||||
},
|
},
|
||||||
], function(err, res) {
|
], function(err, res) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
|
@ -642,12 +642,22 @@ Storage.prototype._completeTxNotesData = function(walletId, notes, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.fetchTxNotes = function(walletId, cb) {
|
/**
|
||||||
|
* fetchTxNotes. Times are in UNIX EPOCH (seconds)
|
||||||
|
*
|
||||||
|
* @param walletId
|
||||||
|
* @param opts.minTs
|
||||||
|
*/
|
||||||
|
Storage.prototype.fetchTxNotes = function(walletId, opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.db.collection(collections.TX_NOTES).find({
|
var filter = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
}).toArray(function(err, result) {
|
};
|
||||||
|
if (_.isNumber(opts.minTs)) filter.editedOn = {
|
||||||
|
$gte: opts.minTs
|
||||||
|
};
|
||||||
|
this.db.collection(collections.TX_NOTES).find(filter).toArray(function(err, result) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
var notes = _.compact(_.map(result, function(note) {
|
var notes = _.compact(_.map(result, function(note) {
|
||||||
if (!note.body) return;
|
if (!note.body) return;
|
||||||
|
|
|
@ -3834,7 +3834,9 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#editTxNote', function(done) {
|
});
|
||||||
|
|
||||||
|
describe('Transaction notes', function(done) {
|
||||||
var server, wallet;
|
var server, wallet;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helpers.createAndJoinWallet(1, 2, function(s, w) {
|
helpers.createAndJoinWallet(1, 2, function(s, w) {
|
||||||
|
@ -3970,31 +3972,6 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should not leak notes between wallets', function(done) {
|
|
||||||
helpers.createAndJoinWallet(1, 1, {
|
|
||||||
offset: 2
|
|
||||||
}, function(server2, wallet2) {
|
|
||||||
server.editTxNote({
|
|
||||||
txid: '123',
|
|
||||||
body: 'note body'
|
|
||||||
}, function(err) {
|
|
||||||
should.not.exist(err);
|
|
||||||
server.getTxNote({
|
|
||||||
txid: '123',
|
|
||||||
}, function(err, note) {
|
|
||||||
should.not.exist(err);
|
|
||||||
should.exist(note);
|
|
||||||
server2.getTxNote({
|
|
||||||
txid: '123',
|
|
||||||
}, function(err, note) {
|
|
||||||
should.not.exist(err);
|
|
||||||
should.not.exist(note);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should be possible to remove a note', function(done) {
|
it('should be possible to remove a note', function(done) {
|
||||||
server.editTxNote({
|
server.editTxNote({
|
||||||
txid: '123',
|
txid: '123',
|
||||||
|
@ -4059,6 +4036,90 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should get all notes edited past a given date', function(done) {
|
||||||
|
var clock = sinon.useFakeTimers('Date');
|
||||||
|
async.series([
|
||||||
|
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.should.be.empty;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.editTxNote({
|
||||||
|
txid: '123',
|
||||||
|
body: 'note body'
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({
|
||||||
|
minTs: 0,
|
||||||
|
}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.length.should.equal(1);
|
||||||
|
notes[0].txid.should.equal('123');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
clock.tick(60 * 1000);
|
||||||
|
server.editTxNote({
|
||||||
|
txid: '456',
|
||||||
|
body: 'another note'
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({
|
||||||
|
minTs: 0,
|
||||||
|
}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.length.should.equal(2);
|
||||||
|
_.difference(_.pluck(notes, 'txid'), ['123', '456']).should.be.empty;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({
|
||||||
|
minTs: 50,
|
||||||
|
}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.length.should.equal(1);
|
||||||
|
notes[0].txid.should.equal('456');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
clock.tick(60 * 1000);
|
||||||
|
server.editTxNote({
|
||||||
|
txid: '123',
|
||||||
|
body: 'an edit'
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({
|
||||||
|
minTs: 100,
|
||||||
|
}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.length.should.equal(1);
|
||||||
|
notes[0].txid.should.equal('123');
|
||||||
|
notes[0].body.should.equal('an edit');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
server.getTxNotes({}, function(err, notes) {
|
||||||
|
should.not.exist(err);
|
||||||
|
notes.length.should.equal(2);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function(err) {
|
||||||
|
should.not.exist(err);
|
||||||
|
clock.restore();
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue