notifications: clearAlert

This commit is contained in:
Girish Ramakrishnan
2023-03-26 14:18:37 +02:00
parent 0ab73d6c5e
commit 61ba3cbfc2
3 changed files with 28 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ exports = module.exports = {
ALERT_MANUAL_APP_UPDATE: 'manualAppUpdate',
alert,
clearAlert,
// exported for testing
_add: add
@@ -233,25 +234,29 @@ async function alert(id, title, message) {
const result = await getByTitle(title);
if (message) {
if (!result) {
return await add(null /* eventId */, title, message);
} else {
await update(result, {
eventId: null,
title,
message,
acknowledged: false,
creationTime: new Date()
});
return result.id;
}
if (!result) {
return await add(null /* eventId */, title, message);
} else {
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
return null;
await update(result, {
eventId: null,
title,
message,
acknowledged: false,
creationTime: new Date()
});
return result.id;
}
}
// id is unused but nice to search code
async function clearAlert(id, title) {
assert.strictEqual(typeof id, 'string');
assert.strictEqual(typeof title, 'string');
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
return null;
}
async function onEvent(id, action, source, data) {
assert.strictEqual(typeof id, 'string');
assert.strictEqual(typeof action, 'string');