Notifications

Settings Notifications
User Panel
This commit is contained in:
Paolo Arena
2022-07-23 17:48:33 +02:00
parent e9ce597027
commit b06f1e4ab8
19 changed files with 472 additions and 121 deletions

View File

@@ -14,6 +14,10 @@ const sendemail = require('../sendemail');
const globalTables = require('../tools/globalTables');
const {SendNotif} = require('../models/sendnotif');
const shared_consts = require('../tools/shared_nodejs');
const _ = require('lodash');
router.post('/', authenticate, (req, res) => {
@@ -37,10 +41,12 @@ router.post('/', authenticate, (req, res) => {
return myevent.findOneAndUpdate({id}, {$set: fieldtochange}, {
new: false,
upsert: true,
}).then((recmyevent) => {
}).then(async (recmyevent) => {
// tools.mylog('myevent:', myevent);
// tools.mylog('already exist');
globalTables.sendNotif(res, myrec.idapp, req.user, recmyevent);
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC
await SendNotif.saveAndSendNotif(recmyevent, req, res);
return res;
}).then((res) => {
res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
@@ -53,8 +59,11 @@ router.post('/', authenticate, (req, res) => {
let idobj = writeresult._id;
myevent.findById(idobj).then((recmyevent) => {
globalTables.sendNotif(res, myrec.idapp, req.user, recmyevent);
res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC
return SendNotif.saveAndSendNotif(recmyevent, req, res).then((ris) => {
return res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
});
});
});
}
@@ -72,8 +81,11 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
return res.status(404).send();
}
if (notify === '1')
globalTables.sendNotif(res, idapp, req.user, recmyevent);
if (notify === '1') {
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC
SendNotif.saveAndSendNotif(recmyevent, req, res);
}
tools.mylog('DELETED ', recmyevent.descr, recmyevent._id);