notifications: fix pagination of listByUserIdPaged
we have to filter in sql query, otherwise we don't get consistent per page count
This commit is contained in:
@@ -103,21 +103,28 @@ function del(id, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function listByUserIdPaged(userId, page, perPage, callback) {
|
||||
function listByUserIdPaged(userId, options, page, perPage, callback) {
|
||||
assert.strictEqual(typeof userId, 'string');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
assert(options.acknowledged === null || typeof options.acknowledged === 'boolean');
|
||||
assert.strictEqual(typeof page, 'number');
|
||||
assert.strictEqual(typeof perPage, 'number');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var data = [ userId ];
|
||||
var query = 'SELECT ' + NOTIFICATION_FIELDS + ' FROM notifications WHERE userId=?';
|
||||
let args = [ userId ];
|
||||
let query = `SELECT ${NOTIFICATION_FIELDS} FROM notifications WHERE userId=?`;
|
||||
|
||||
if ('acknowledged' in options) {
|
||||
query += ' AND acknowledged=?';
|
||||
args.push(options.acknowledged);
|
||||
}
|
||||
|
||||
query += ' ORDER BY creationTime DESC LIMIT ?,?';
|
||||
|
||||
data.push((page-1)*perPage);
|
||||
data.push(perPage);
|
||||
args.push((page-1)*perPage);
|
||||
args.push(perPage);
|
||||
|
||||
database.query(query, data, function (error, results) {
|
||||
database.query(query, args, function (error, results) {
|
||||
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
|
||||
|
||||
results.forEach(postProcess);
|
||||
|
||||
Reference in New Issue
Block a user