notifications: can also mark it as unread

This commit is contained in:
Girish Ramakrishnan
2021-04-21 12:00:07 -07:00
parent bb3f9744fb
commit d437acebe2
5 changed files with 37 additions and 31 deletions
+20 -15
View File
@@ -1,12 +1,12 @@
'use strict';
exports = module.exports = {
get: get,
getByUserIdAndTitle: getByUserIdAndTitle,
add: add,
update: update,
del: del,
listByUserIdPaged: listByUserIdPaged,
get,
getByUserIdAndTitle,
add,
update,
del,
list,
// exported for testing
_clear: clear
@@ -103,22 +103,27 @@ function del(id, 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');
function list(filters, page, perPage, callback) {
assert.strictEqual(typeof filters, 'object');
assert.strictEqual(typeof page, 'number');
assert.strictEqual(typeof perPage, 'number');
assert.strictEqual(typeof callback, 'function');
let args = [ userId ];
let query = `SELECT ${NOTIFICATION_FIELDS} FROM notifications WHERE userId=?`;
let args = [];
if ('acknowledged' in options) {
query += ' AND acknowledged=?';
args.push(options.acknowledged);
let where = [];
if ('userId' in filters) {
where.push('userId=?');
args.push(filters.userId);
}
if ('acknowledged' in filters) {
where.push('acknowledged=?');
args.push(filters.acknowledged);
}
let query = `SELECT ${NOTIFICATION_FIELDS} FROM notifications`;
if (where.length) query += ' WHERE ' + where.join(' AND ');
query += ' ORDER BY creationTime DESC LIMIT ?,?';
args.push((page-1)*perPage);