++ poter inviare un msg telegram ai appartenenti ai Circuiti RIS.

This commit is contained in:
Surya Paolo
2024-04-23 22:47:20 +02:00
parent 68b4403138
commit 49ecb3edea
14 changed files with 831 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ process.env.LINK_UPDATE_PWD = '/updatepwd';
process.env.LINK_CHECK_UPDATES = '/checkupdates';
process.env.KEY_APP_ID = 'KKPPAA5KJK435J3KSS9F9D8S9F8SD98F9SDF';
// console.log("Starting Node with : " + file);
console.log("Starting Node with: " + file);
require('dotenv').config({ path: file });
process.env.DATABASE = process.env.DATABASE || 'FreePlanet';

View File

@@ -38,6 +38,8 @@ let options = {
// keepAliveInitialDelay: 300000 // keepAliveInitialDelay is the number of milliseconds to wait before initiating keepAlive on the socket.
};
console.log('process.env.AUTH_MONGODB', process.env.AUTH_MONGODB);
if (process.env.AUTH_MONGODB === '1') {
options.auth = {
authSource: "admin",

View File

@@ -563,7 +563,7 @@ UserSchema.methods.generateAuthToken = function (req) {
user.lasttimeonline = new Date();
return user.save().then(() => {
console.log('Salvato refreshToken su DB', refreshToken);
// console.log('Salvato refreshToken su DB', refreshToken);
// console.log("TOKEN CREATO IN LOGIN : " + token);
return { token, refreshToken };
}).catch(err => {
@@ -2746,6 +2746,19 @@ UserSchema.statics.ifAlreadyInCircuit = async function (idapp, usernameOrig, cir
}).lean();
};
//** Get true if in 'profile.mycircuits' exist at least one circuit */
UserSchema.statics.ExistAtLeastOneCircuit = async function (idapp, username) {
// Controllo se è stato più inserito
return await User.countDocuments({
idapp,
username,
'profile.mycircuits': {
$ne: [],
},
});
};
UserSchema.statics.countUsersInGroup = async function (idapp, groupnameDest) {
// Controllo se è stato già inserito

View File

@@ -54,7 +54,7 @@ router.post('/', authenticate, async (req, res) => {
if (myitem === null) {
myitem = subscriptionModel;
tools.mylogshow('Subscription NOT EXISTED IN DB, so I use this created!')
// tools.mylogshow('Subscription NOT EXISTED IN DB, so I use this created!')
} else {
myitem.endpoint = subscriptionModel.endpoint;
myitem.keys = subscriptionModel.keys;

View File

@@ -51,7 +51,7 @@ let credentials = null;
if ((process.env.NODE_ENV === 'production')) {
console.log('*** AMBIENTE DI PRODUZIONE !!!!')
console.log('*** AMBIENTE DI PRODUZIONE (Aprile 2024) !!!!')
} else if (process.env.NODE_ENV === 'test') {
console.log('*** ### AMBIENTE DI TEST ')
}

View File

@@ -275,6 +275,7 @@ const Menu = {
MSG_SI_INVITATI_NO_7REQ_INVITATI: emoji.get('incoming_envelope') +
'Inv e NO 7 Req',
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
MSGAPPARTIENE_CIRCUITI_RIS: 'Invia a Utenti dei Circuiti RIS',
MSGPAOLO: emoji.get('incoming_envelope') + ' Invia a PAOLO',
RESTART_SRV: emoji.get('incoming_envelope') + 'Restart-NodeJs',
REBOOT_SRV: emoji.get('incoming_envelope') + 'Reboot-VPS!',
@@ -471,6 +472,7 @@ const Destin = {
PAOLO: 9,
DOMANDA: 10,
RISPOSTA: 11,
APPARTIENE_CIRCUITO_RIS: 20,
};
const StatusMSGALL = {
@@ -2014,6 +2016,8 @@ class Telegram {
await this.menumsgAll(msg);
} else if (testo === Menu.MSGSTAFF) {
await this.menumsgStaff(msg);
} else if (testo === Menu.MSGAPPARTIENE_CIRCUITI_RIS) {
await this.menumsgAppartieneCircuitiRis(msg);
} else if (testo === Menu.MSGPAOLO) {
await this.menumsgPaolo(msg);
} else if (cmd1 === Menu.EXECSH) {
@@ -2422,6 +2426,8 @@ class Telegram {
return 'STAFF';
else if (destin === Destin.PAOLO)
return 'PAOLO';
else if (destin === Destin.APPARTIENE_CIRCUITO_RIS)
return 'APPARTIENE_CIRCUITO_RIS';
else if (destin === Destin.NO_7_REQ)
return 'No 7 Requisiti';
else if (destin === Destin.NO_9_REQ)
@@ -2453,6 +2459,10 @@ class Telegram {
await this.menumsgGenerico(msg, Destin.STAFF);
}
async menumsgAppartieneCircuitiRis(msg) {
await this.menumsgGenerico(msg, Destin.APPARTIENE_CIRCUITO_RIS);
}
async menumsgPaolo(msg) {
await this.menumsgGenerico(msg, Destin.PAOLO);
}
@@ -2971,6 +2981,8 @@ class Telegram {
// NOTHING
} else {
let contanumutenti = 0;
let usersall = null;
let myusername = '';
@@ -3012,6 +3024,7 @@ class Telegram {
// TEST usersall = await User.getUsersTelegALL(rec.user.idapp, 'paoloar77');
for (const utente of usersall) {
let FormDaMostrare = null;
@@ -3029,6 +3042,8 @@ class Telegram {
let invia = false;
if (destin === Destin.STAFF) {
invia = User.isManager(utente.perm);
} else if (destin === Destin.APPARTIENE_CIRCUITO_RIS) {
invia = await User.ExistAtLeastOneCircuit(utente.idapp, utente.username);
} else if (destin === Destin.TUTTI) {
invia = true;
} else if (destin === Destin.PAOLO) {
@@ -3057,6 +3072,7 @@ class Telegram {
preparatesto += utente.name + ' ' + utente.surname + '(' +
utente.username + ')' + '\n';
} else if (cmd === CONTA_SOLO) {
contanumutenti++;
// Niente
} else if (cmd === CHEDI_SE_IMBARCARTI) {
textdainviare = tools.gettranslate('VUOI_IMBARCARTI', lang);
@@ -3123,7 +3139,7 @@ class Telegram {
let msgris = '';
if (cmd === CONTA_SOLO) {
msgris = nummsgsent + ' ' +
msgris = contanumutenti + ' ' +
getstr(this.getlang(msg), 'MSG_MSG_TOSENT');
} else if (cmd === NOME_COGNOME) {
msgris = nummsgsent + ' ' + 'Utenti';