- 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:
Paolo Arena
2019-10-24 23:30:45 +02:00
parent 51ca2da45f
commit c8c4f57d16
10 changed files with 211 additions and 90 deletions

View File

@@ -0,0 +1,34 @@
p Ciao #{name},
p #{usernameorig} ti ha inviato questo messaggio dalla pagina
span (#{infoevent}):
p #{message}
p
p Per rispondere al messaggio clicca qui:
div.divbtn <a href=#{strlinkreply} target="_blank">
button.btn.btn-lg Rispondi</a>
p Cordiali Saluti
p Supporto #{nomeapp}
style(type="text/css").
html, body {
padding: 0;
margin: 0;
}
.divbtn {
display: flex;
align-items: center;
justify-content: center;
}
.btn-lg {
padding: 5px;
margin: 5px;
font-size: 26px;
cursor: pointer;
color: white;
background: #027be3 !important;
border-radius: 28px;
}

View File

@@ -0,0 +1 @@
=`${usernameorig} tu ha inviato un nuovo messaggio`

View File

@@ -54,6 +54,14 @@ const OperatorSchema = new Schema({
}, },
}); });
OperatorSchema.statics.getEmailByUsername = async function (idapp, username) {
const Operator = this;
return await Operator.findOne({idapp, username}, (err, arrrec) => {
return (arrrec) ? arrrec.email : '';
});
};
OperatorSchema.statics.executeQueryTable = function (idapp, params) { OperatorSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params); return tools.executeQueryTable(this, idapp, params);
}; };

View File

@@ -15,19 +15,19 @@ const sendmsgSchema = new Schema({
idapp: { idapp: {
type: String, type: String,
}, },
userId: { origin: {
userId: { type: String },
page: { type: String },
event_id: { type: String }
},
dest: {
idapp: { type: String, },
username: { type: String },
},
message: {
type: String, type: String,
}, },
idappDest: { datemsg: {
type: Number,
},
usernameDest: {
type: String,
},
msg: {
type: String,
},
date: {
type: Date, type: Date,
}, },
read: { read: {
@@ -38,22 +38,52 @@ const sendmsgSchema = new Schema({
type: Boolean, type: Boolean,
default: false default: false
}, },
originpage: {
type: String,
},
}); });
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) { sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, username, idapp) {
const SendMsg = this; const SendMsg = this;
return SendMsg.find({userId, idapp}, (err, arrmsg) => { // Filter my msg
console.log('ris arrmsg:', arrmsg); //
// (userId or dest.username === username) and idapp
console.log('userId', userId);
return SendMsg.find({
$and: [
{
$or: [
{ 'origin.userId': userId },
{ 'dest.username': username }]
},
{ idapp }
]
}, (err, arrmsg) => {
// console.log('ris arrmsg:', arrmsg);
return arrmsg return arrmsg
}); });
// return SendMsg.find(
// {
// $and: [
// {
// $or: [
// { 'dest.username': username },
// { userId: userId }
// ],
// },
// {
// idapp
// }
// ]
// }, (err, arrmsg) => {
// console.log('ris arrmsg:', arrmsg);
// return arrmsg
// });
}; };
var SendMsg = mongoose.model('SendMsg', sendMsgSchema); const SendMsg = mongoose.model('SendMsg', sendmsgSchema);
module.exports = { SendMsg }; module.exports = { SendMsg };

View File

@@ -16,6 +16,7 @@ const { Operator } = require('../models/operator');
const { Where } = require('../models/where'); const { Where } = require('../models/where');
const { MyEvent } = require('../models/myevent'); const { MyEvent } = require('../models/myevent');
const { Contribtype } = require('../models/contribtype'); const { Contribtype } = require('../models/contribtype');
const { SendMsg } = require('../models/sendmsg');
const tools = require('../tools/general'); const tools = require('../tools/general');
@@ -86,42 +87,6 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, (req, res) => {
}); });
router.get(process.env.LINK_CHECK_UPDATES, authenticate, (req, res) => {
const userId = req.user._id;
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
if (!ObjectID.isValid(userId)) {
return res.status(404).send();
}
cfgserver.find().then((arrcfgrec) => {
if (!arrcfgrec)
return res.status(404).send();
// ++Todo: Add to Log Stat ....
if (req.user) {
// If User is Admin, then send user Lists
if (User.isAdmin(req.user)) {
// Send UsersList
return User.getUsersList(req.user.idapp).then(usersList => {
return res.send({ cfgServer: arrcfgrec, usersList });
})
}
}
res.send({ cfgServer: arrcfgrec });
}).catch((e) => {
console.log(e);
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
});
});
// Invio la Nuova Password richiesta dal reset! // Invio la Nuova Password richiesta dal reset!
// Ritorna il token per poter effettuare le chiamate... // Ritorna il token per poter effettuare le chiamate...
router.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => { router.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => {
@@ -165,6 +130,8 @@ function getTableByTableName(tablename) {
mytable = Booking; mytable = Booking;
else if (tablename === 'operators') else if (tablename === 'operators')
mytable = Operator; mytable = Operator;
else if (tablename === 'sendmsgs')
mytable = SendMsg;
else if (tablename === 'wheres') else if (tablename === 'wheres')
mytable = Where; mytable = Where;
else if (tablename === 'myevents') else if (tablename === 'myevents')
@@ -335,9 +302,10 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
const sall = req.params.sall; const sall = req.params.sall;
// var category = req.params.category; // var category = req.params.category;
tools.mylog('loadsite : ', req.params); // tools.mylog('loadsite : ', req.params);
let bookedevent = []; let bookedevent = [];
let msgs = [];
if (userId !== '0') { if (userId !== '0') {
// LOGGED WITH USERID // LOGGED WITH USERID
@@ -350,10 +318,16 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
const wheres = Where.findAllIdApp(idapp); const wheres = Where.findAllIdApp(idapp);
const contribtype = Contribtype.findAllIdApp(idapp); const contribtype = Contribtype.findAllIdApp(idapp);
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype]) return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, msgs])
.then((arrdata) => { .then((arrdata) => {
console.table(arrdata); // console.table(arrdata);
res.send({ bookedevent: arrdata[0], eventlist: arrdata[1], operators: arrdata[2], wheres: arrdata[3], contribtype: arrdata[4] }); res.send({
bookedevent: arrdata[0],
eventlist: arrdata[1],
operators: arrdata[2],
wheres: arrdata[3],
contribtype: arrdata[4],
});
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
@@ -362,5 +336,52 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
}); });
router.get(process.env.LINK_CHECK_UPDATES, authenticate, (req, res) => {
const userId = req.user._id;
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
if (!ObjectID.isValid(userId)) {
return res.status(404).send();
}
cfgserver.find().then((arrcfgrec) => {
if (!arrcfgrec)
return res.status(404).send();
// ++Todo: Add to Log Stat ....
// const sall = '0';
msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
let usersList = null;
if (req.user) {
// If User is Admin, then send user Lists
if (User.isAdmin(req.user)) {
// Send UsersList
usersList = User.getUsersList(req.user.idapp)
}
}
return Promise.all([usersList, msgs])
.then((arrdata) => {
// console.table(arrdata);
return res.send({
cfgServer: arrcfgrec,
usersList: arrdata[0],
msgs: arrdata[1],
});
});
}).catch((e) => {
console.log(e);
res.status(400).send({ code: server_constants.RIS_CODE_ERR, msg: e });
});
});
module.exports = router; module.exports = router;

View File

@@ -101,7 +101,7 @@ router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
} }
// Extract all the todos of the userId only // Extract all the todos of the userId only
MyEvent.findAllByUserIdAndIdApp(userId, idapp, sall).then((recevent) => { return MyEvent.findAllByUserIdAndIdApp(userId, idapp, sall).then((recevent) => {
res.send({ recevent }); res.send({ recevent });
}).catch((e) => { }).catch((e) => {
console.log(e); console.log(e);

View File

@@ -6,7 +6,8 @@ const server_constants = require('../tools/server_constants');
const { authenticate } = require('../middleware/authenticate'); const { authenticate } = require('../middleware/authenticate');
const { Sendmsg } = require('../models/Sendmsg'); const { Operator } = require('../models/operator');
const { SendMsg } = require('../models/sendmsg');
const { ObjectID } = require('mongodb'); const { ObjectID } = require('mongodb');
@@ -14,37 +15,55 @@ const sendemail = require('../sendemail');
const _ = require('lodash'); const _ = require('lodash');
function sendNotif(res, idapp, user, recmsg) { async function sendNotif(res, idapp, user, recmsg) {
//++Todo: tools.sendNotificationToUser //++Todo: tools.sendNotificationToUser
// Send Msg // Extract the Email Destination
sendemail.sendEmail_Msg(res, user.lang, user.email, user, idapp, recmsg); 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) => { router.post('/', authenticate, (req, res) => {
tools.mylog('INIZIO - Sendmsg'); tools.mylog('INIZIO - SendMsg');
// tools.mylog('req.body', req.body); // tools.mylog('req.body', req.body);
const body = _.pick(req.body, tools.allfieldSendmsg()); const body = _.pick(req.body, tools.allfieldSendMsg());
tools.mylog('crea Sendmsg'); tools.mylog('crea SendMsg');
const Sendmsg = new Sendmsg(body); 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; if (check.exit) return check.ret;
// console.log('fieldtochange', fieldtochange); // console.log('fieldtochange', fieldtochange);
Sendmsg._id = new ObjectID(); myrecmsg._id = new ObjectID();
return Sendmsg.save().then((writeresult) => { return myrecmsg.save()
let idobj = writeresult._id; .then((writeresult) => {
let idobj = writeresult._id;
Sendmsg.findById(idobj) myrecmsg._id = idobj;
.then((recmsg) => {
sendNotif(res, body.idapp, req.user, recmsg);
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
});
});
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; const idapp = req.params.idapp;
// var category = req.params.category; // var category = req.params.category;
tools.mylog('GET SendmsgS : ', req.params); tools.mylog('GET SendMsgS : ', req.params);
if (!ObjectID.isValid(userId)) { if (!ObjectID.isValid(userId)) {
return res.status(404).send(); return res.status(404).send();
@@ -65,7 +84,7 @@ router.get('/:userId/:idapp', authenticate, (req, res) => {
} }
// Extract all the todos of the userId only // Extract all the todos of the userId only
Sendmsg.findAllByUserIdAndIdApp(userId, idapp).then((msgall) => { return SendMsg.findAllByUserIdAndIdApp(userId, idapp).then((msgall) => {
res.send({ msgall }); res.send({ msgall });
}).catch((e) => { }).catch((e) => {
console.log(e); console.log(e);

View File

@@ -55,8 +55,7 @@ module.exports = {
// htmlToText: false // htmlToText: false
}); });
return email
email
.send({ .send({
template: template, template: template,
message: { message: {
@@ -64,8 +63,13 @@ module.exports = {
}, },
locals: mylocalsconf, locals: mylocalsconf,
}) })
.then(console.log) .then((ris) => {
.catch(console.error); return !!ris
})
.catch((err) => {
console.error(err);
return false
});
}, },
sendEmail_Normale: function (to, subject, html, replyTo) { sendEmail_Normale: function (to, subject, html, replyTo) {
@@ -219,7 +223,7 @@ module.exports = {
} }
}, },
sendEmail_Msg: function (res, lang, emailto, user, idapp, recbooking) { sendEmail_Msg: function (res, lang, emailto, user, idapp, recmsg) {
tools.mylog('sendEmail_Msg'); tools.mylog('sendEmail_Msg');
tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp); tools.mylog('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp);
@@ -229,13 +233,14 @@ module.exports = {
nomeapp: tools.getNomeAppByIdApp(idapp), nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name, name: user.name,
surname: user.surname, surname: user.surname,
usernameorig: user.name + ' ' + user.surname,
emailto: emailto, emailto: emailto,
msgbooking: recbooking.msgbooking, message: recmsg.message,
eventtextplain: tools.removeSpecialCharForEmail(recbooking.infoevent), infoevent: recmsg.origin.infoevent,
event: recbooking.infoevent, strlinkreply: tools.getHostByIdApp(idapp) + '/messages/' + recmsg._id
}; };
this.sendEmail_base('msg/sendmsg/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp)); return this.sendEmail_base('msg/sendmsg/' + lang, user, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
// Send Email also to the Admin // Send Email also to the Admin
// this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf); // this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);

View File

@@ -32,6 +32,7 @@ require('./models/user');
require('./models/subscribers'); require('./models/subscribers');
require('./models/cfgserver'); require('./models/cfgserver');
require('./models/booking'); require('./models/booking');
require('./models/sendmsg');
const mysql_func = require('./mysql/mysql_func'); const mysql_func = require('./mysql/mysql_func');
@@ -41,6 +42,7 @@ const newsletter_router = require('./router/newsletter_router');
const booking_router = require('./router/booking_router'); const booking_router = require('./router/booking_router');
const myevent_router = require('./router/myevent_router'); const myevent_router = require('./router/myevent_router');
const subscribe_router = require('./router/subscribe_router'); const subscribe_router = require('./router/subscribe_router');
const sendmsg_router = require('./router/sendmsg_router');
const email_router = require('./router/email_router'); const email_router = require('./router/email_router');
const todos_router = require('./router/todos_router'); const todos_router = require('./router/todos_router');
const projects_router = require('./router/projects_router'); const projects_router = require('./router/projects_router');
@@ -91,6 +93,7 @@ app.use(i18n.init);
// Use Routes // Use Routes
app.use('/', index_router); app.use('/', index_router);
app.use('/subscribe', subscribe_router); app.use('/subscribe', subscribe_router);
app.use('/sendmsg', sendmsg_router);
app.use('/push', push_router); app.use('/push', push_router);
app.use('/signup_news', newsletter_router); app.use('/signup_news', newsletter_router);
app.use('/booking', booking_router); app.use('/booking', booking_router);

View File

@@ -59,8 +59,8 @@ module.exports = {
console.error(args) console.error(args)
}, },
allfieldSendmsg: function () { allfieldSendMsg: function () {
return ['userId', 'date', 'usernameDest', 'msg', 'originPage'] return ['userId', 'dest', 'message', 'datemsg', 'read', 'deleted', 'origin', 'idapp']
}, },
allfieldTodo: function () { allfieldTodo: function () {