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:
@@ -3,7 +3,7 @@
|
||||
exports = module.exports = {
|
||||
get,
|
||||
ack,
|
||||
getAllPaged,
|
||||
listByUserIdPaged,
|
||||
|
||||
onEvent,
|
||||
|
||||
@@ -80,19 +80,18 @@ function ack(id, callback) {
|
||||
}
|
||||
|
||||
// if acknowledged === null we return all, otherwise yes or no based on acknowledged as a boolean
|
||||
function getAllPaged(userId, acknowledged, page, perPage, callback) {
|
||||
function listByUserIdPaged(userId, options, page, perPage, callback) {
|
||||
assert.strictEqual(typeof userId, 'string');
|
||||
assert(acknowledged === null || typeof acknowledged === 'boolean');
|
||||
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');
|
||||
|
||||
notificationdb.listByUserIdPaged(userId, page, perPage, function (error, result) {
|
||||
notificationdb.listByUserIdPaged(userId, options, page, perPage, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
if (acknowledged === null) return callback(null, result);
|
||||
|
||||
callback(null, result.filter(function (r) { return r.acknowledged === acknowledged; }));
|
||||
callback(null, result);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user