Added notifications - (WIP, boilerplate)

This commit is contained in:
Isaac Abadi
2022-11-24 14:54:08 -05:00
parent 1c6b7815fe
commit 5e08ca004a
16 changed files with 333 additions and 4 deletions

View File

@@ -1992,6 +1992,44 @@ app.post('/api/changeRolePermissions', optionalJwt, async (req, res) => {
res.send({success: success});
});
// notifications
app.post('/api/getNotifications', optionalJwt, async (req, res) => {
const uuid = req.user.uid;
const notifications = await db_api.getRecords('notifications', {user_uid: uuid});
res.send({notifications: notifications});
});
// set notifications to read
app.post('/api/setNotificationsToRead', optionalJwt, async (req, res) => {
const uids = req.body.uids;
// TODO: do a bulk update
const success = true; // await db_api.updateRecords('notifications', {user_uid: uuid});
res.send({success: success});
});
app.post('/api/deleteNotification', optionalJwt, async (req, res) => {
const uid = req.body.uid;
const success = await db_api.removeRecord('notifications', {uid: uid});
res.send({success: success});
});
app.post('/api/deleteAllNotifications', optionalJwt, async (req, res) => {
const uuid = req.user.uid;
const success = await db_api.removeAllRecords('notifications', {user_uid: uuid});
res.send({success: success});
});
// web server
app.use(function(req, res, next) {
//if the request is not html then move along
var accept = req.accepts('html', 'json', 'xml');

View File

@@ -58,6 +58,10 @@ const tables = {
name: 'tasks',
primary_key: 'key'
},
notifications: {
name: 'notifications',
primary_key: 'uid'
},
test: {
name: 'test'
}

13
backend/notifications.js Normal file
View File

@@ -0,0 +1,13 @@
const utils = require('./utils');
const logger = require('./logger');
const db_api = require('./db');
exports.sendNotification = async () => {
// TODO: hook into third party service
const notification = {}
await db_api.insertRecordIntoTable('notifications', notification);
return notification;
}