vedere le Richieste di Fiducia solo se si è verificati Telegram

Corretto il mio account che doveva confermare in automatico... non lo faceva...
"Riregistrarsi se l'invitante non ha ancora confermato l'invito.
Annullo la richiesta precedente. (inviando un msg di annullamento. (Si è già registrato con un alto invito.)"
CMyEditor: non posso andare in edit sul HTML (nella table)
Aggiornare il msg di benvenuto ! (prendere da msgtemplate)
Dal Profilo: è possibile inviarsi il messaggio da condividere agli Amici
Visualizzare la data d'inserimento dell'annuncio e l'ultima modifica fatta
Link alla pagina di un Evento o Bene o Servizio !
Se aggiornamento: mettere messaggio che dice di chiudere e riaprire per aggiornare.
Quando un utente chiede di entrare nel Gruppo, mettere l'abilitazione anche su Telegram. (e correggere il msg)
This commit is contained in:
paoloar77
2022-03-06 00:48:33 +01:00
parent 4bc406fba6
commit 466fdd597d
14 changed files with 686 additions and 784 deletions

View File

@@ -82,58 +82,6 @@ router.post('/downline', authenticate, async (req, res) => {
});
router.post('/msgnave', authenticate, async (req, res) => {
const idapp = req.body.idapp;
let mydata = req.body;
try {
let ris = null;
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SINGOLO) {
let mymsg = '';
if (!!mydata.username_mitt) {
mymsg = '[' + tools.getres__('MSG_SEND_FROM', res) + ' ' + mydata.username_mitt + ' a ' + mydata.username + ']:' + tools.ACAPO;
}
mymsg += mydata.msgpar1;
// ris = await telegrambot.sendMsgTelegram(idapp, mydata.username, mymsg, true, mydata.username_mitt); // Anche a STAFF
ris = await telegrambot.sendMsgTelegram(idapp, mydata.username, mymsg, true); // Anche a STAFF
} else
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata, res);
if (ris)
res.send({ code: server_constants.RIS_CODE_OK, ris });
else
res.send({ code: server_constants.RIS_CODE_ERR, ris: null });
} catch (e) {
res.status(400).send(e);
}
});
router.post('/msgflotta', authenticate, async (req, res) => {
const idapp = req.body.idapp;
let mydata = req.body;
try {
let ris = null;
ris = await telegrambot.sendMsgTelegramToNave(idapp, mydata, res);
if (ris)
res.send({ code: server_constants.RIS_CODE_OK, ris });
else
res.send({ code: server_constants.RIS_CODE_ERR, ris: null });
} catch (e) {
res.status(400).send(e);
}
});
router.post('/getmsg_templates', authenticate, async (req, res) => {
const idapp = req.body.idapp;

View File

@@ -334,6 +334,10 @@ router.post('/settable', authenticate, async (req, res) => {
}
}
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
mytablerec.date_updated = new Date();
}
return mytablerec.save().
then(async (rec) => {
@@ -1160,7 +1164,7 @@ function load(req, res, version) {
myuser = arrdata[26];
if (myuser) {
myuser.password = '';
myuser._doc.calcstat = arrdata[13];
myuser.calcstat = arrdata[13];
}
} catch (e) {}
}

View File

@@ -23,7 +23,7 @@ router.post('/page', authenticate, function(req, res, next) {
let idGood = req.body.idGood;
let idapp = req.body.idapp;
return MyGood.getMyGoodByIdkill(idapp, idGood).
return MyGood.getMyRecById(idapp, idGood).
then((ris) => {
if (ris) {

View File

@@ -23,7 +23,7 @@ router.post('/page', authenticate, function(req, res, next) {
let idSkill = req.body.idSkill;
let idapp = req.body.idapp;
return MySkill.getMySkillByIdkill(idapp, idSkill).
return MySkill.getMyRecById(idapp, idSkill).
then((ris) => {
if (ris) {

View File

@@ -1,18 +1,20 @@
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', false);
const Subscription = mongoose.model('subscribers');
// const q = require('q');
const webpush = require('web-push');
const tools = require('../tools/general');
const { authenticate } = require('../middleware/authenticate');
const {authenticate} = require('../middleware/authenticate');
const shared_consts = require('../tools/shared_nodejs');
const server_constants = require('../tools/server_constants');
const { User } = require('../models/user');
const {User} = require('../models/user');
const globalTables = require('../tools/globalTables');
router.post('/', (req, res) => {
const payload = {
@@ -23,14 +25,14 @@ router.post('/', (req, res) => {
icon: req.body.icon,
image: req.body.image,
badge: req.body.badge,
tag: req.body.tag
tag: req.body.tag,
};
Subscription.find({}, (err, subscriptions) => {
if (err) {
console.error(`Error occurred while getting subscriptions`);
res.status(500).json({
error: 'Technical error occurred'
error: 'Technical error occurred',
});
} else {
@@ -40,8 +42,8 @@ router.post('/', (req, res) => {
endpoint: subscription.endpoint,
keys: {
p256dh: subscription.keys.p256dh,
auth: subscription.keys.auth
}
auth: subscription.keys.auth,
},
};
const pushPayload = JSON.stringify(payload);
@@ -52,23 +54,23 @@ router.post('/', (req, res) => {
publicKey: process.env.PUBLIC_VAPI_KEY,
},
TTL: payload.ttl,
headers: {}
headers: {},
};
webpush.sendNotification(
pushSubscription,
pushPayload,
pushOptions
pushSubscription,
pushPayload,
pushOptions,
).then((value) => {
resolve({
status: true,
endpoint: subscription.endpoint,
data: value
data: value,
});
}).catch((err) => {
reject({
status: false,
endpoint: subscription.endpoint,
data: err
data: err,
});
});
});
@@ -77,84 +79,31 @@ router.post('/', (req, res) => {
console.info(pushResults);
});
res.json({
data: 'Push triggered'
data: 'Push triggered',
});
}
});
});
async function SendMsgToAll(idapp, params) {
const arrusers = await User.find({ idapp },
{
username: 1,
name: 1,
surname: 1,
}
);
let msgsent = 0;
for (const user of arrusers) {
await SendMsgTo(idapp, user.username, params);
msgsent++;
}
return msgsent;
}
async function SendMsgToParam(idapp, params) {
const arrusers = await User.find({ idapp },
{
username: 1,
name: 1,
surname: 1,
'profile.socio': 1,
'profile.socioresidente': 1,
}
);
let msgsent = 0;
for (const user of arrusers) {
let invia = false;
if (params.typemsg === shared_consts.TypeMsg.SEND_TO_SOCI) {
invia = user.profile.socio;
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_SOCIO_RESIDENTE) {
invia = user.profile.socioresidente;
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_CONSIGLIO) {
invia = user.profile.consiglio;
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_NON_SOCI) {
invia = !user.profile.socio;
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_PAOLO) {
invia = user.username === 'paoloar77';
} else {
invia = true;
}
if (invia) {
await SendMsgTo(idapp, user.username, params);
msgsent++;
}
}
return msgsent;
}
async function SendMsgTo(idapp, username, params) {
return User.find({ idapp, username }).then((arrusers) => {
return User.find({idapp, username}).then((arrusers) => {
if (arrusers !== null) {
for (const user of arrusers) {
tools.sendNotificationToUser(user._id, params.title, params.content, params.openUrl, params.openUrl2, params.tag, params.actions)
.then(ris => {
if (ris) {
tools.sendNotificationToUser(user._id, params.title, params.content,
params.openUrl, params.openUrl2, params.tag, params.actions).
then(ris => {
if (ris) {
} else {
// already sent the error on calling sendNotificationToUser
}
})
.catch(e => {
console.error(e.message);
})
} else {
// already sent the error on calling sendNotificationToUser
}
}).
catch(e => {
console.error(e.message);
});
}
}
});
@@ -169,28 +118,33 @@ router.post('/send', authenticate, async (req, res) => {
let nummsg = 0;
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTutor(req.user.perm))) {
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
!User.isTutor(req.user.perm))) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
return res.status(404).
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
}
try {
if (params.typemsg === shared_consts.TypeMsg.SEND_TO_ALL) {
nummsg = await SendMsgToAll(idapp, params);
} else {
nummsg = await SendMsgToParam(idapp, params);
}
params.typesend = shared_consts.TypeSend.PUSH_NOTIFICATION;
params.sendreally = true;
const ris = await globalTables.SendMsgToParam(idapp, params);
return res.send({ code: server_constants.RIS_CODE_OK, msg: nummsg + ' Msg Inviati !', nummsg });
}catch (e) {
return res.send({ code: server_constants.RIS_CODE_ERR, msg: nummsg + ' Msg Inviati !' });
return res.send({
code: server_constants.RIS_CODE_OK,
msg: ris.nummsgsent + ' Msg Inviati su ' + ris.numrec + ' !',
nummsg: ris.nummsgsent,
});
} catch (e) {
return res.send(
{code: server_constants.RIS_CODE_ERR, msg: nummsg + ' Msg Inviati !'});
}
});
router.get('/', (req, res) => {
res.json({
data: 'Invalid Request Bad'
data: 'Invalid Request Bad',
});
});
module.exports = router;

View File

@@ -250,13 +250,10 @@ router.post('/', async (req, res) => {
await User.setaportador_solidario(user.idapp, user.username,
user.aportador_solidario);
const myuser = await User.findOne({_id: trovarec._id});
const myuser = await User.findOne({_id: trovarec._id}).lean();
if (myuser) {
await telegrambot.askConfirmationUserRegistration(myuser.idapp,
shared_consts.CallFunz.REGISTRATION, myuser,
myuser.profile.username_telegram, myuser.profile.firstname_telegram,
myuser.profile.lastname_telegram);
await telegrambot.askConfirmationUser(myuser.idapp, shared_consts.CallFunz.REGISTRATION, myuser);
const token = await myuser.generateAuthToken(req);
res.header('x-auth', token).send(myuser);
@@ -1088,4 +1085,24 @@ router.post('/dbop', authenticate, async (req, res) => {
});
router.post('/mgt', authenticate, async (req, res) => {
const mydata = req.body.mydata;
idapp = req.body.idapp;
locale = req.body.locale;
try {
const {nummsgsent, numrec } = await telegrambot.sendMsgFromSiteToBotTelegram(idapp, req.user, mydata);
return res.send({numrec, nummsgsent });
} catch (e) {
res.status(400).send();
res.send({code: server_constants.RIS_CODE_ERR, msg: e});
console.log(e.message);
}
});
module.exports = router;