Notifications
Settings Notifications User Panel
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user