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:
Girish Ramakrishnan
2021-04-20 13:49:05 -07:00
parent fbceb67df9
commit bb3f9744fb
3 changed files with 28 additions and 22 deletions

View File

@@ -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);
});
}