Notification: Set a new Friendship and Accepted Friendship

This commit is contained in:
Paolo Arena
2022-07-26 15:46:39 +02:00
parent b06f1e4ab8
commit 3515914f17
15 changed files with 411 additions and 150 deletions

View File

@@ -339,9 +339,24 @@ router.post('/settable', authenticate, async (req, res) => {
});
}
let setnotif = false;
let typedir = 0;
let typeid = 0;
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);
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
typeid = (params.table === shared_consts.TABLES_MYGOODS) ? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD : shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
setnotif = true;
}
if (shared_consts.TABLES_EVENTS_NOTIFICATION.includes(params.table)) {
typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC;
setnotif = true;
}
if (setnotif) {
SendNotif.createNewNotification(req, res, params.table, myrec, typedir, typeid);
}
return res.send(myrec);

View File

@@ -44,9 +44,7 @@ router.post('/', authenticate, (req, res) => {
}).then(async (recmyevent) => {
// tools.mylog('myevent:', myevent);
// tools.mylog('already exist');
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC
await SendNotif.saveAndSendNotif(recmyevent, req, res);
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});
@@ -61,9 +59,8 @@ 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
return SendNotif.saveAndSendNotif(recmyevent, req, res).then((ris) => {
return res.send({code: server_constants.RIS_CODE_OK, msg: '', id: recmyevent._id});
});
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});
});
});
}
@@ -82,9 +79,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
}
if (notify === '1') {
recmyevent.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS
recmyevent.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC
SendNotif.saveAndSendNotif(recmyevent, req, res);
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

@@ -23,13 +23,19 @@ const {ObjectID} = require('mongodb');
//GET orders
router.post('/page', authenticate, function(req, res, next) {
//++TODO: PERMESSI ???
const {SendNotif} = require('../models/sendnotif');
try {
let table = req.body.table;
let id = req.body.id;
let idapp = req.body.idapp;
const username = req.user.username ? req.user.username : '';
// Check if ìs a Notif to read
const idnotif = req.body.idnotif ? req.body.idnotif : '';
SendNotif.setNotifAsRead(idapp, username, idnotif);
let mytable = null;
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
mytable = globalTables.getTableByTableName(table);

View File

@@ -101,11 +101,10 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
return res.status(404).send({code: server_constants.RIS_CODE_NOT_MY_USERNAME});
}
// Extract all the todos of the userId only
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then((arrnotif) => {
// const wait = new Promise((resolve, reject) => {
// setTimeout(() => {
res.send({arrnotif});
return res.send({arrnotif});
// }, 2000);
// });

View File

@@ -378,15 +378,16 @@ router.patch('/:id', authenticate, (req, res) => {
});
router.post('/profile', authenticate, (req, res) => {
const usernameOrig = req.user.username;
const username = req.body['username'];
const idapp = req.body.idapp;
const locale = req.body.locale;
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
//++Todo: controlla che tipo di dati ha il permesso di leggere
// Check if ìs a Notif to read
SendNotif.setNotifAsRead(idapp, username, idnotif);
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
try {
return User.getUserProfileByUsername(idapp, username, req.user.username,
@@ -457,8 +458,10 @@ router.post('/notifs', authenticate, async (req, res) => {
if (tools.isArray(notifs) && notifs.length >= 0) {
myuser.profile.notifs = notifs;
myuser.save();
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
}
}
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
} catch (e) {
tools.mylogserr('Error profile: ', e);
res.status(400).send();
@@ -577,7 +580,7 @@ router.post('/setperm', authenticate, (req, res) => {
const body = _.pick(req.body, ['idapp', 'username', 'perm']);
tools.mylog('SETPERM = ' + req.token);
User.setPermissionsById(res.user._id, body).then(() => {
User.setPermissionsById(req.user._id, body).then(() => {
res.status(200).send();
}, () => {
res.status(400).send();