Skip to content

Commit

Permalink
add 'and' option,default is 'or'
Browse files Browse the repository at this point in the history
  • Loading branch information
ByCnck committed Oct 8, 2017
1 parent 3e63fd6 commit d230eaa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,16 @@ private.list = function (filter, cb) {
uiaCurrencyJoin = 'inner join transfers ut on ut.transactionId = t.id and ut.currency = "' + filter.currency + '" '
}

var connector = "or";
if (filter.and) {
connector = "and";
}

library.dbLite.query("select count(t.id) " +
"from trs t " +
"inner join blocks b on t.blockId = b.id " + uiaCurrencyJoin +
(fields_or.length || owner ? "where " : "") + " " +
(fields_or.length ? "(" + fields_or.join(' or ') + ") " : "") + (fields_or.length && owner ? " and " + owner : owner), params, { "count": Number }, function (err, rows) {
(fields_or.length ? "(" + fields_or.join(' ' + connector + ' ') + ") " : "") + (fields_or.length && owner ? " and " + owner : owner), params, { "count": Number }, function (err, rows) {
if (err) {
return cb(err);
}
Expand All @@ -475,7 +480,7 @@ private.list = function (filter, cb) {
"from trs t " +
"inner join blocks b on t.blockId = b.id " + uiaCurrencyJoin +
(fields_or.length || owner ? "where " : "") + " " +
(fields_or.length ? "(" + fields_or.join(' or ') + ") " : "") + (fields_or.length && owner ? " and " + owner : owner) + " " +
(fields_or.length ? "(" + fields_or.join(' ' + connector + ' ') + ") " : "") + (fields_or.length && owner ? " and " + owner : owner) + " " +
(filter.orderBy ? 'order by ' + sortBy + ' ' + sortMethod : '') + " " +
(filter.limit ? 'limit $limit' : '') + " " +
(filter.offset ? 'offset $offset' : ''), params, ['t_id', 'b_height', 't_blockId', 't_type', 't_timestamp', 't_senderPublicKey', 't_senderId', 't_recipientId', 't_amount', 't_fee', 't_signature', 't_signSignature', 't_signatures', 't_args', 't_message', 'confirmations'], function (err, rows) {
Expand Down Expand Up @@ -798,6 +803,11 @@ shared.getTransactions = function (req, cb) {
type: "string",
minimum: 1,
maximum: 22
},
and:{
type:"integer",
minimum: 0,
maximum: 1
}
}
}, function (err) {
Expand Down

0 comments on commit d230eaa

Please sign in to comment.