- Delete Event with ask confirmation
- Fix dateStart only 1 view if is the same day - Sending a message from the Event Page: to a user or to a "Event" - Add button "Ask Info" - Starting view msg into the messagepopup component
This commit is contained in:
@@ -6,7 +6,8 @@ const server_constants = require('../tools/server_constants');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const { Sendmsg } = require('../models/Sendmsg');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { SendMsg } = require('../models/sendmsg');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
@@ -14,37 +15,55 @@ const sendemail = require('../sendemail');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
function sendNotif(res, idapp, user, recmsg) {
|
||||
async function sendNotif(res, idapp, user, recmsg) {
|
||||
//++Todo: tools.sendNotificationToUser
|
||||
|
||||
// Send Msg
|
||||
sendemail.sendEmail_Msg(res, user.lang, user.email, user, idapp, recmsg);
|
||||
// Extract the Email Destination
|
||||
const emaildest = await Operator.getEmailByUsername(recmsg.dest.idapp, recmsg.dest.username);
|
||||
console.log('emaildest', emaildest);
|
||||
|
||||
// Send Msg by EMAIL
|
||||
if (emaildest)
|
||||
return await sendemail.sendEmail_Msg(res, user.lang, emaildest, user, idapp, recmsg);
|
||||
|
||||
}
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
tools.mylog('INIZIO - Sendmsg');
|
||||
tools.mylog('INIZIO - SendMsg');
|
||||
// tools.mylog('req.body', req.body);
|
||||
const body = _.pick(req.body, tools.allfieldSendmsg());
|
||||
const body = _.pick(req.body, tools.allfieldSendMsg());
|
||||
|
||||
tools.mylog('crea Sendmsg');
|
||||
const Sendmsg = new Sendmsg(body);
|
||||
tools.mylog('crea SendMsg');
|
||||
const myrecmsg = new SendMsg(body);
|
||||
|
||||
const check = tools.checkUserOk(Sendmsg.userId, req.user._id);
|
||||
const check = tools.checkUserOk(myrecmsg.origin.userId, req.user._id);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
Sendmsg._id = new ObjectID();
|
||||
return Sendmsg.save().then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
myrecmsg._id = new ObjectID();
|
||||
return myrecmsg.save()
|
||||
.then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
Sendmsg.findById(idobj)
|
||||
.then((recmsg) => {
|
||||
sendNotif(res, body.idapp, req.user, recmsg);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
||||
});
|
||||
});
|
||||
myrecmsg._id = idobj;
|
||||
|
||||
return SendMsg.findById(idobj)
|
||||
.then((recmsg) => {
|
||||
// Add this field because I don't want to add into the database
|
||||
recmsg.origin.infoevent = body.origin.infoevent;
|
||||
|
||||
return sendNotif(res, body.idapp, req.user, recmsg).then((ris) => {
|
||||
if (ris)
|
||||
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);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
@@ -53,7 +72,7 @@ router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
const idapp = req.params.idapp;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET SendmsgS : ', req.params);
|
||||
tools.mylog('GET SendMsgS : ', req.params);
|
||||
|
||||
if (!ObjectID.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
@@ -65,7 +84,7 @@ router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Sendmsg.findAllByUserIdAndIdApp(userId, idapp).then((msgall) => {
|
||||
return SendMsg.findAllByUserIdAndIdApp(userId, idapp).then((msgall) => {
|
||||
res.send({ msgall });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user