- 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:
34
emails/msg/sendmsg/it/html.pug
Normal file
34
emails/msg/sendmsg/it/html.pug
Normal 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;
|
||||
|
||||
}
|
||||
1
emails/msg/sendmsg/it/subject.pug
Normal file
1
emails/msg/sendmsg/it/subject.pug
Normal file
@@ -0,0 +1 @@
|
||||
=`${usernameorig} tu ha inviato un nuovo messaggio`
|
||||
@@ -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) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
@@ -15,19 +15,19 @@ const sendmsgSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
userId: {
|
||||
origin: {
|
||||
userId: { type: String },
|
||||
page: { type: String },
|
||||
event_id: { type: String }
|
||||
},
|
||||
dest: {
|
||||
idapp: { type: String, },
|
||||
username: { type: String },
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
},
|
||||
idappDest: {
|
||||
type: Number,
|
||||
},
|
||||
usernameDest: {
|
||||
type: String,
|
||||
},
|
||||
msg: {
|
||||
type: String,
|
||||
},
|
||||
date: {
|
||||
datemsg: {
|
||||
type: Date,
|
||||
},
|
||||
read: {
|
||||
@@ -38,22 +38,52 @@ const sendmsgSchema = new Schema({
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
originpage: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp) {
|
||||
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, username, idapp) {
|
||||
const SendMsg = this;
|
||||
|
||||
return SendMsg.find({userId, idapp}, (err, arrmsg) => {
|
||||
console.log('ris arrmsg:', arrmsg);
|
||||
// Filter my msg
|
||||
//
|
||||
// (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 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 };
|
||||
|
||||
@@ -16,6 +16,7 @@ const { Operator } = require('../models/operator');
|
||||
const { Where } = require('../models/where');
|
||||
const { MyEvent } = require('../models/myevent');
|
||||
const { Contribtype } = require('../models/contribtype');
|
||||
const { SendMsg } = require('../models/sendmsg');
|
||||
|
||||
|
||||
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!
|
||||
// Ritorna il token per poter effettuare le chiamate...
|
||||
router.post(process.env.LINK_UPDATE_PASSWORD, (req, res) => {
|
||||
@@ -165,6 +130,8 @@ function getTableByTableName(tablename) {
|
||||
mytable = Booking;
|
||||
else if (tablename === 'operators')
|
||||
mytable = Operator;
|
||||
else if (tablename === 'sendmsgs')
|
||||
mytable = SendMsg;
|
||||
else if (tablename === 'wheres')
|
||||
mytable = Where;
|
||||
else if (tablename === 'myevents')
|
||||
@@ -335,9 +302,10 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
const sall = req.params.sall;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('loadsite : ', req.params);
|
||||
// tools.mylog('loadsite : ', req.params);
|
||||
|
||||
let bookedevent = [];
|
||||
let msgs = [];
|
||||
|
||||
if (userId !== '0') {
|
||||
// LOGGED WITH USERID
|
||||
@@ -350,10 +318,16 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
const wheres = Where.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) => {
|
||||
console.table(arrdata);
|
||||
res.send({ bookedevent: arrdata[0], eventlist: arrdata[1], operators: arrdata[2], wheres: arrdata[3], contribtype: arrdata[4] });
|
||||
// console.table(arrdata);
|
||||
res.send({
|
||||
bookedevent: arrdata[0],
|
||||
eventlist: arrdata[1],
|
||||
operators: arrdata[2],
|
||||
wheres: arrdata[3],
|
||||
contribtype: arrdata[4],
|
||||
});
|
||||
})
|
||||
.catch((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;
|
||||
|
||||
@@ -101,7 +101,7 @@ router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
// 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 });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -55,8 +55,7 @@ module.exports = {
|
||||
// htmlToText: false
|
||||
});
|
||||
|
||||
|
||||
email
|
||||
return email
|
||||
.send({
|
||||
template: template,
|
||||
message: {
|
||||
@@ -64,8 +63,13 @@ module.exports = {
|
||||
},
|
||||
locals: mylocalsconf,
|
||||
})
|
||||
.then(console.log)
|
||||
.catch(console.error);
|
||||
.then((ris) => {
|
||||
return !!ris
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return false
|
||||
});
|
||||
},
|
||||
|
||||
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('tools.getNomeAppByIdApp(idapp)', tools.getNomeAppByIdApp(idapp), idapp);
|
||||
@@ -229,13 +233,14 @@ module.exports = {
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
usernameorig: user.name + ' ' + user.surname,
|
||||
emailto: emailto,
|
||||
msgbooking: recbooking.msgbooking,
|
||||
eventtextplain: tools.removeSpecialCharForEmail(recbooking.infoevent),
|
||||
event: recbooking.infoevent,
|
||||
message: recmsg.message,
|
||||
infoevent: recmsg.origin.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
|
||||
// this.sendEmail_base('admin/sendmsg/' + lang, user, tools.getAdminEmailByIdApp(idapp), mylocalsconf);
|
||||
|
||||
@@ -32,6 +32,7 @@ require('./models/user');
|
||||
require('./models/subscribers');
|
||||
require('./models/cfgserver');
|
||||
require('./models/booking');
|
||||
require('./models/sendmsg');
|
||||
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 myevent_router = require('./router/myevent_router');
|
||||
const subscribe_router = require('./router/subscribe_router');
|
||||
const sendmsg_router = require('./router/sendmsg_router');
|
||||
const email_router = require('./router/email_router');
|
||||
const todos_router = require('./router/todos_router');
|
||||
const projects_router = require('./router/projects_router');
|
||||
@@ -91,6 +93,7 @@ app.use(i18n.init);
|
||||
// Use Routes
|
||||
app.use('/', index_router);
|
||||
app.use('/subscribe', subscribe_router);
|
||||
app.use('/sendmsg', sendmsg_router);
|
||||
app.use('/push', push_router);
|
||||
app.use('/signup_news', newsletter_router);
|
||||
app.use('/booking', booking_router);
|
||||
|
||||
@@ -59,8 +59,8 @@ module.exports = {
|
||||
console.error(args)
|
||||
},
|
||||
|
||||
allfieldSendmsg: function () {
|
||||
return ['userId', 'date', 'usernameDest', 'msg', 'originPage']
|
||||
allfieldSendMsg: function () {
|
||||
return ['userId', 'dest', 'message', 'datemsg', 'read', 'deleted', 'origin', 'idapp']
|
||||
},
|
||||
|
||||
allfieldTodo: function () {
|
||||
|
||||
Reference in New Issue
Block a user