Notifications
Settings Notifications User Panel
This commit is contained in:
@@ -253,6 +253,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS) {
|
||||
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
|
||||
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
|
||||
@@ -338,6 +339,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||
// E' un annuncio, pertanto mando una notifica a "tutti"
|
||||
SendNotif.createNewNotification(req, res, params.table, myrec, shared_consts.TypeNotifs.TYPEDIR_BACHECA, shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD);
|
||||
}
|
||||
|
||||
return res.send(myrec);
|
||||
}).catch((e) => {
|
||||
console.error('settable', e.message);
|
||||
@@ -1301,7 +1307,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
||||
|
||||
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
let last_notifs = SendNotif.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
let last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 20);
|
||||
|
||||
let usersList = null;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ const { User } = require('../models/user');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { SendMsg } = require('../models/sendmsg');
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
@@ -46,9 +48,15 @@ router.post('/', authenticate, (req, res) => {
|
||||
// Add this field because I don't want to add into the database
|
||||
recmsg.source.infoevent = body.source.infoevent;
|
||||
|
||||
return await globalTables.sendNotif(res, body.idapp, req.user, recmsg).then((ris) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
||||
recmsg.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
||||
recmsg.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC;
|
||||
return SendNotif.saveAndSendNotif(recmyevent, req, res).then((out) => {
|
||||
if (out)
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
||||
else
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
})
|
||||
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
|
||||
@@ -6,49 +6,24 @@ const server_constants = require('../tools/server_constants');
|
||||
|
||||
const {authenticate} = require('../middleware/authenticate');
|
||||
|
||||
const {User} = require('../models/user');
|
||||
const {Operator} = require('../models/operator');
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
router.post('/', authenticate, async (req, res) => {
|
||||
tools.mylog('INIZIO - SendNotif');
|
||||
// tools.mylog('req.body', req.body);
|
||||
const body = _.pick(req.body, tools.allfieldSendNotif());
|
||||
|
||||
tools.mylog('crea SendNotif');
|
||||
const myrecnotif = new SendNotif(body);
|
||||
let myrecnotif = new SendNotif(body);
|
||||
|
||||
const check = tools.checkUserOk(myrecnotif.sender, req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
return myrecnotif.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
myrecnotif._id = idobj;
|
||||
|
||||
return SendNotif.findById(idobj).then(async (recnotif) => {
|
||||
// Add this field because I don't want to add into the database
|
||||
|
||||
return await globalTables.sendNotif(res, body.idapp, req.user, recnotif).then((ris) => {
|
||||
return res.send({code: server_constants.RIS_CODE_OK, notif: '', id: recnotif._id});
|
||||
});
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
// res.status(400).send(e);
|
||||
const recout = await SendNotif.saveAndSendNotif(myrecnotif, req, res);
|
||||
if (recout) {
|
||||
return res.send({code: server_constants.RIS_CODE_OK, notif: '', record: recout});
|
||||
} else {
|
||||
return res.send({code: server_constants.RIS_CODE_ERR, notif: ''});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -74,6 +49,46 @@ router.get('/setall/:username/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const myid = req.params.id;
|
||||
const username_call = req.user.username;
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
await SendNotif.findOneAndRemove({idapp, _id: myid});
|
||||
return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
});
|
||||
|
||||
router.get('/delall/:username/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const username_call = req.user.username;
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
const ris = await SendNotif.deleteMany({idapp, dest: username});
|
||||
if (ris)
|
||||
return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
return res.send(false);
|
||||
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
tools.mylog('GET NotifS : ', req.params);
|
||||
const username = req.params.username;
|
||||
|
||||
@@ -56,6 +56,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
} else {
|
||||
myitem.endpoint = subscriptionModel.endpoint;
|
||||
myitem.keys = subscriptionModel.keys;
|
||||
myitem.createDate = new Date();
|
||||
}
|
||||
|
||||
return myitem.save((err, subscription) => {
|
||||
|
||||
@@ -422,10 +422,12 @@ router.post('/panel', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
const myuser = await User.findOne({idapp, username},
|
||||
{username: 1, email: 1, verified_by_aportador: 1, aportador_solidario: 1,
|
||||
{
|
||||
username: 1, email: 1, verified_by_aportador: 1, aportador_solidario: 1,
|
||||
lasttimeonline: 1,
|
||||
deleted: 1,
|
||||
profile: 1}).lean();
|
||||
profile: 1,
|
||||
}).lean();
|
||||
if (!!myuser) {
|
||||
res.send(myuser);
|
||||
} else {
|
||||
@@ -450,7 +452,6 @@ router.post('/notifs', authenticate, async (req, res) => {
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (!!myuser) {
|
||||
if (tools.isArray(notifs) && notifs.length >= 0) {
|
||||
@@ -465,7 +466,6 @@ router.post('/notifs', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
router.post('/login', (req, res) => {
|
||||
var body = _.pick(req.body,
|
||||
['username', 'password', 'idapp', 'keyappid', 'lang']);
|
||||
|
||||
Reference in New Issue
Block a user