Notification New Group

This commit is contained in:
paoloar77
2022-07-28 23:27:51 +02:00
parent 7cda5dbb8b
commit 241e4255d4
9 changed files with 63 additions and 32 deletions

View File

@@ -327,21 +327,12 @@ router.post('/settable', authenticate, async (req, res) => {
}
// tools.mylog('rec', rec);
}).then((myrec) => {
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
// nuovo Record:
// aggiungi il creatore al gruppo stesso
return User.setGroupsCmd(mydata.idapp, req.user.username,
myrec.groupname,
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
return res.send(myrec);
});
}
}).then(async (myrec) => {
let setnotif = false;
let typedir = 0;
let typeid = 0;
let groupNameDest = '';
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
@@ -358,13 +349,25 @@ router.post('/settable', authenticate, async (req, res) => {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(params.table)) {
typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
groupNameDest = myrec ? myrec.groupname : '';
setnotif = true;
}
if (setnotif) {
SendNotif.createNewNotification(req, res, params.table, myrec, typedir, typeid);
await SendNotif.createNewNotification(req, res, {groupNameDest}, params.table, myrec, typedir, typeid);
}
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
// nuovo Record:
// aggiungi il creatore al gruppo stesso
return User.setGroupsCmd(mydata.idapp, req.user.username,
myrec.groupname,
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
return res.send(myrec);
});
}
return res.send(myrec);
}).catch((e) => {
console.error('settable', e.message);

View File

@@ -44,7 +44,7 @@ router.post('/', authenticate, (req, res) => {
}).then(async (recmyevent) => {
// tools.mylog('myevent:', myevent);
// tools.mylog('already exist');
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
return res;
}).then((res) => {
res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
@@ -59,7 +59,7 @@ router.post('/', authenticate, (req, res) => {
myevent.findById(idobj).then((recmyevent) => {
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_NEW_REC);
return res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
});
});
@@ -79,7 +79,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
}
if (notify === '1') {
SendNotif.createNewNotification(req, res, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC);
SendNotif.createNewNotification(req, res, {}, shared_consts.TABLES_MYEVENTS, recmyevent, shared_consts.TypeNotifs.TYPEDIR_EVENTS, shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC);
}
tools.mylog('DELETED ', recmyevent.descr, recmyevent._id);

View File

@@ -29,8 +29,16 @@ async function getGroupRecAdminsInfo(idapp, data) {
router.post('/load', authenticate, async (req, res) => {
const idapp = req.body.idapp;
const groupname = req.body.groupname;
const usernameOrig = req.user.username;
try {
const {SendNotif} = require('../models/sendnotif');
// Check if ìs a Notif to read
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
let data = await MyGroup.findOne({idapp, groupname}, whatshow).lean();