diff --git a/filelog.txt b/filelog.txt
index 551bfdc..e1a4589 100644
--- a/filelog.txt
+++ b/filelog.txt
@@ -47,3 +47,49 @@ Ven 23/06 ORE 14:08: USER [paoloar77]: link da condividere
Sab 30/09 ORE 00:21: USER [SuryaArena]: vai al sito
Sab 30/09 ORE 00:32: USER [SuryaArena]: vai al sito
+
+Gio 12/10 ORE 11:11: USER [paoloar77]: prova
+
+Gio 12/10 ORE 11:48: USER [paoloar77]: prova
+
+Gio 12/10 ORE 12:07: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:07: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:09: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:10: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:10: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:13: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:14: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:16: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:21: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:33: USER [paoloar77]: prova
+
+Gio 12/10 ORE 12:33: USER [SuryaArena]: ciao
+
+Gio 12/10 ORE 12:33: USER [SuryaArena]: prova
+
+Gio 12/10 ORE 12:45: USER [SuryaArena]: bottone
+
+Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
+
+Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
+
+Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
+
+Gio 12/10 ORE 14:52: USER [paoloar77]: bottone
+
+Gio 12/10 ORE 14:57: USER [paoloar77]: bottone
+
+Gio 12/10 ORE 15:06: USER [paoloar77]: bottone
+
+Ven 13/10 ORE 11:05: USER [SuryaArena]: bottone
+
+Ven 13/10 ORE 11:40: USER [SuryaArena]: bottone
diff --git a/logtrans.txt b/logtrans.txt
index 5f201bf..ebcc38f 100644
--- a/logtrans.txt
+++ b/logtrans.txt
@@ -24,4 +24,76 @@ paogruppo2: 320 RIS]
Sab 30/09 ORE 13:32: [Circuito RIS Bologna]: Inviate Monete da SuryaArena a paoloar77 1 RIS [causale: aaa]
Saldi:
SuryaArena: -1 RIS]
-paoloar77: 11 RIS]
\ No newline at end of file
+paoloar77: 11 RIS]
+Lun 09/10 ORE 09:04: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -2 RIS]
+SuryaArena2: 1 RIS]
+Lun 09/10 ORE 09:21: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -3 RIS]
+SuryaArena2: 2 RIS]
+Lun 09/10 ORE 10:25: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -4 RIS]
+SuryaArena2: 3 RIS]
+Lun 09/10 ORE 10:26: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -5 RIS]
+SuryaArena2: 4 RIS]
+Lun 09/10 ORE 23:26: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -2 RIS]
+SuryaArena2: 1 RIS]
+Lun 09/10 ORE 23:36: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -3 RIS]
+SuryaArena2: 2 RIS]
+Lun 09/10 ORE 23:36: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -4 RIS]
+SuryaArena2: 3 RIS]
+Mar 10/10 ORE 00:04: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -5 RIS]
+SuryaArena2: 4 RIS]
+Mar 10/10 ORE 00:21: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -6 RIS]
+SuryaArena2: 5 RIS]
+Mar 10/10 ORE 00:34: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -7 RIS]
+SuryaArena2: 6 RIS]
+Mar 10/10 ORE 22:47: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
+Saldi:
+paoloar77: -8 RIS]
+PaoTEST1: 1 RIS]
+Mar 10/10 ORE 22:49: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
+Saldi:
+paoloar77: -9 RIS]
+PaoTEST1: 2 RIS]
+Mar 10/10 ORE 23:08: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 2 RIS [causale: ]
+Saldi:
+paoloar77: -11 RIS]
+PaoTEST1: 4 RIS]
+Mar 10/10 ORE 23:13: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 3 RIS [causale: ]
+Saldi:
+paoloar77: -14 RIS]
+PaoTEST1: 7 RIS]
+Mar 10/10 ORE 23:22: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
+Saldi:
+paoloar77: -15 RIS]
+PaoTEST1: 8 RIS]
+Mer 11/10 ORE 22:33: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
+Saldi:
+paoloar77: -16 RIS]
+PaoTEST1: 9 RIS]
+Gio 12/10 ORE 08:05: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
+Saldi:
+paoloar77: -17 RIS]
+PaoTEST1: 10 RIS]
+Gio 12/10 ORE 08:06: [Circuito RIS Rimini]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
+Saldi:
+paoloar77: -18 RIS]
+SuryaArena2: 7 RIS]
\ No newline at end of file
diff --git a/src/server/locales/it.json b/src/server/locales/it.json
index ed7fc41..6fbc594 100644
--- a/src/server/locales/it.json
+++ b/src/server/locales/it.json
@@ -58,9 +58,9 @@
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il %s da parte di %s",
"CIRCUIT_ELIMINATO": "Il %s è stato eliminato da parte di %s",
"FIDO_IMPOSTATO_ADMINS_CIRCUIT": "✅ l'utente %s è stato abilitato al Fido (%s RIS) sul '%s' (da parte di %s)",
- "FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato abilitato al Fido fino a -%s sul '%s' (da parte di %s)",
+ "FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto di Gruppo %s è stato abilitato al Fido fino a -%s sul '%s' (da parte di %s)",
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del '%s' (da parte di %s)",
- "ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato accettato a far parte del '%s' (da parte di %s)",
+ "ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto di Gruppo %s è stato accettato a far parte del '%s' (da parte di %s)",
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
"FIDO_IMPOSTATO": "✅ Ti è stata attivata la possibilità di utilizzare il fido (Fiducia Concessa) fino a %s RIS da %s sul '%s'.",
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del '%s'",
diff --git a/src/server/models/account.js b/src/server/models/account.js
index 39ab80f..1bb2993 100755
--- a/src/server/models/account.js
+++ b/src/server/models/account.js
@@ -66,6 +66,14 @@ const AccountSchema = new Schema({
type: Number,
default: 0,
},
+ saldo_pend: {
+ type: Number,
+ default: 0,
+ },
+ totTransato_pend: {
+ type: Number,
+ default: 0,
+ },
regulation_ok: {
type: Boolean,
},
@@ -150,23 +158,69 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
}
};
-AccountSchema.methods.addtoSaldoSave = async function (amount) {
- const account = this;
+AccountSchema.methods.calcPending = async function (mittente) {
+ try {
+ const account = this;
- if (account) {
- account.saldo = account.saldo + amount;
- if (!account.totTransato) {
- account.totTransato = 0;
+ const { SendNotif } = require('../models/sendnotif');
+ const { Circuit } = require('../models/circuit');
+
+ // *** Calc Pending Transactions ***
+
+ const circuit = await Circuit.getCircuitById(account.circuitId);
+ if (circuit) {
+ let prec_saldo_pend = account.saldo_pend;
+ let prec_totTransato_pend = account.totTransato_pend;
+ let transatopending = 0;
+
+ if (mittente) {
+ let pendingtransactionsMittente = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
+ let saldopendingMitt = pendingtransactionsMittente.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
+ transatopending = pendingtransactionsMittente.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
+
+ account.saldo_pend = account.saldo - saldopendingMitt;
+ } else {
+ // let pendingtransactionsDest = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
+
+ // let saldopendingDest = pendingtransactionsDest.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
+ // transatopending = pendingtransactionsDest.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
+
+ // account.saldo_pend = account.saldo + saldopendingDest;
+ account.saldo_pend = account.saldo;
+ }
+ account.totTransato_pend = account.totTransato + transatopending;
+
+ if (prec_saldo_pend !== account.saldo_pend || prec_totTransato_pend !== account.totTransato_pend) {
+
+ const myaccountupdate = {
+ saldo_pend: account.saldo_pend,
+ totTransato_pend: account.totTransato_pend,
+ };
+
+ // Update Record
+ return await Account.findByIdAndUpdate(account.id,
+ {
+ $set: myaccountupdate
+ }).then((ris) => {
+ console.log('calcPending', ris);
+ }).catch((err) => {
+ console.error('calcPending', err);
+ });
+
+
+ }
}
- account.totTransato += Math.abs(amount);
- account.date_updated = new Date();
- return await account.save();
+
+
+ // -----
+
+ } catch (e) {
+ console.error(e);
}
- return null;
-};
+}
-AccountSchema.statics.addtoSaldo = async function (myaccount, amount) {
+AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
const Account = this;
try {
@@ -184,10 +238,16 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount) {
myaccountupdate.totTransato = myaccount.totTransato;
myaccountupdate.date_updated = myaccount.date_updated;
- return await Account.updateOne({ _id: myaccount.id },
+ const ris = await Account.updateOne({ _id: myaccount.id },
{
$set: myaccountupdate
});
+
+
+ await myaccount.calcPending(mitt);
+
+ return ris;
+
}
} catch (e) {
console.error('error', e);
@@ -244,8 +304,11 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
deperibile: false,
importo_iniziale: 0,
saldo: 0,
+ saldo_pend: 0,
fidoConcesso: 0,
qta_maxConcessa: 0,
+ totTransato: 0,
+ totTransato_pend: 0,
});
if (contocom) {
@@ -372,11 +435,11 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
$match: {
$expr: {
$and: [
+ { $eq: ['$idapp', '$$idapp'] },
{ $eq: ['$typedir', '$$typedir'] },
{ $eq: ['$typeid', '$$typeid'] },
{ $eq: ['$status', 0] },
{ $eq: ['$sender', '$$username'] },
- { $eq: ['$idapp', '$$idapp'] },
{ $eq: ['$extrarec.circuitname', '$$circuitname'] },
],
},
@@ -397,7 +460,7 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
// console.log('1 - INIZIA getUserAccounts ')
// console.log(aggr1);
- if (ris) {
+ /* if (ris) {
for (const account of ris) {
try {
//++OTTIMIZZARE QUESTA PARTE ! (CON UNA QUERY...)
@@ -416,9 +479,8 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
}
}
- }
+ } */
- // console.log(' 2 - FINE getUserAccounts LEN=', ris.length)
return ris;
} catch (e) {
console.error('getUserAccounts', e);
@@ -482,20 +544,6 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
const ris = await this.aggregate(aggr1);
- const { SendNotif } = require('../models/sendnotif');
-
- if (ris) {
- // tools.startTimeLog('Query Pending')
- for (const account of ris) {
- const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
- const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
- if (saldopending) {
- account.saldo -= saldopending;
- }
- }
- // tools.endTimeLog('Query Pending')
- }
-
return ris;
} catch (e) {
console.error('e', e);
@@ -559,12 +607,16 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
};
-AccountSchema.statics.updateFido = async function (idapp, username, circuitId, fido) {
+AccountSchema.statics.updateFido = async function (idapp, username, groupname, circuitId, fido) {
let paramstoupdate = {
fidoConcesso: fido,
};
- const risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
+ let risult = null;
+ if (groupname)
+ risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
+ else
+ risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
return risult;
};
@@ -606,6 +658,15 @@ AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, ci
{ $pull: { people: { username: { $in: [person_username] } } } });
};
+AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {
+
+ const recaccounts = await Account.find({ idapp });
+
+ for (const account of recaccounts) {
+ await account.calcPending();
+ }
+
+};
const Account = mongoose.model('Account', AccountSchema);
diff --git a/src/server/models/circuit.js b/src/server/models/circuit.js
index db6d59d..bf402c7 100755
--- a/src/server/models/circuit.js
+++ b/src/server/models/circuit.js
@@ -1101,7 +1101,7 @@ CircuitSchema.statics.setFido = async function (idapp, username, circuitName, gr
else
fido = mycircuit.fido_scoperto_default;
- return await Account.updateFido(idapp, username, circuitId, fido);
+ return await Account.updateFido(idapp, username, groupname, circuitId, fido);
}
}
return false;
diff --git a/src/server/models/movement.js b/src/server/models/movement.js
index 35140d8..c1f0bb0 100755
--- a/src/server/models/movement.js
+++ b/src/server/models/movement.js
@@ -113,9 +113,9 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
if (mymov) {
// Update saldo dell'Account
- await Account.addtoSaldo(accountToIdTable, amount);
+ await Account.addtoSaldo(accountToIdTable, amount, true);
- await Account.addtoSaldo(accountFromIdTable, -amount);
+ await Account.addtoSaldo(accountFromIdTable, -amount, false);
return mymov;
}
@@ -681,7 +681,6 @@ MovementSchema.statics.checkIfCoinsAlreadySent = async function (notifId) {
try {
const rec = await MyMovement.findOne({ notifId }, { _id: 1 });
-
return !!rec;
} catch (e) {
diff --git a/src/server/models/myelem.js b/src/server/models/myelem.js
index 2209655..6d64f0e 100755
--- a/src/server/models/myelem.js
+++ b/src/server/models/myelem.js
@@ -143,6 +143,7 @@ const MyElemSchema = new Schema({
anim: animation,
active: {
type: Boolean,
+ default: false,
},
class: {
type: String,
diff --git a/src/server/models/sendnotif.js b/src/server/models/sendnotif.js
index 0b14852..e20d804 100755
--- a/src/server/models/sendnotif.js
+++ b/src/server/models/sendnotif.js
@@ -22,18 +22,22 @@ mongoose.plugin(schema => {
const sendNotifSchema = new Schema({
idapp: {
type: String,
+ index: true,
},
typedir: {
type: Number,
default: 0,
+ index: true,
},
typeid: {
type: Number,
default: 0,
+ index: true,
},
sender: { // mittente
type: String,
default: '',
+ index: true,
},
dest: {
type: String,
@@ -66,6 +70,7 @@ const sendNotifSchema = new Schema({
status: {
type: Number,
default: 0,
+ index: true,
},
typesend: {
type: Number,
@@ -107,6 +112,14 @@ const sendNotifSchema = new Schema({
}
});
+sendNotifSchema.index({ idapp: 1 });
+sendNotifSchema.index({ typedir: 1 });
+sendNotifSchema.index({ typeid: 1 });
+sendNotifSchema.index({ sender: 1 });
+
+sendNotifSchema.index({ idapp: 1, typedir: 1, typeid: 1, status: 1, sender: 1 });
+
+
sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) {
const SendNotif = this;
@@ -368,7 +381,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO) {
if (recnotif.paramsObj.isAdmin) {
if (recnotif.extrarec.groupname) {
- newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', -recnotif.paramsObj.extrarec.fido_scoperto_default_grp, recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
+ newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, -recnotif.paramsObj.extrarec.fido_scoperto_default_grp, recnotif.paramsObj.circuitnameDest,
username_action);
} else {
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT', sender, -recnotif.paramsObj.extrarec.fido_scoperto_default, recnotif.paramsObj.circuitnameDest,
@@ -622,6 +635,8 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
// console.log('myrecout._id', myrecout._id.toString());
+ let risnotif = null;
+
if (save) {
let res = null;
try {
@@ -633,7 +648,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
// console.log('myrecread._id', myrecread._id.toString());
if (myrecread)
- return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
+ risnotif = await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
else
return false;
}
@@ -644,9 +659,12 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
}
} else {
- return await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
+ risnotif = await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
}
+
+ return risnotif;
+
};
sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlysave, userorig) {
@@ -1031,9 +1049,14 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
send = true;
}
}
- } else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
- if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
- shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
+ } else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA
+ || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS
+ || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS
+ ) {
+ if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec)
+ || shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)
+ || shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)
+ ) {
// Estrai la Città, la Provincia e la regione.
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE) &&
@@ -1067,7 +1090,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
}
}
- } else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
+ /*} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
send = true;
@@ -1078,7 +1101,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.CircuitsNotif.STATUS_NEW)) {
send = true;
}
- }
+ }*/
}
if (send) {
@@ -1118,7 +1141,8 @@ sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req,
};
-sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, username, circuitname, groupname) {
+
+sendNotifSchema.statics.getSumPendingTransactionsMittente = async function (idapp, username, circuitname, groupname) {
const SendNotif = this;
try {
@@ -1140,9 +1164,60 @@ sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, usern
};
+sendNotifSchema.statics.getSumPendingTransactionsDest = async function (idapp, username, circuitname, groupname) {
+ const SendNotif = this;
+
+ try {
+ const query = {
+ idapp,
+ sender: username,
+ sendergroup: groupname,
+ typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
+ typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
+ status: 0,
+ 'extrarec.circuitname': circuitname,
+ 'extrarec.dest': username,
+ 'extrarec.groupdest': groupname,
+ };
+
+ return await SendNotif.find(query).lean();
+
+ } catch (e) {
+ console.error('e', e);
+ }
+
+};
+
+sendNotifSchema.statics.updatePendingTransactions = async function (recnotif) {
+
+ const { Circuit } = require('../models/circuit');
+ const { Account } = require('../models/account');
+
+ try {
+ if (recnotif && recnotif.extrarec && recnotif.extrarec.circuitname) {
+
+ const circuit = await Circuit.getCircuitByName(recnotif.idapp, recnotif.extrarec.circuitname);
+
+ const accountdestTable = await Account.getAccountByUsernameAndCircuitId(recnotif.idapp, recnotif.extrarec.dest, circuit._id, true, false, recnotif.extrarec.groupdest, recnotif.extrarec.contoComDest);
+ const accountorigTable = await Account.getAccountByUsernameAndCircuitId(recnotif.idapp, recnotif.sender, circuit._id, true, true, recnotif.extrarec.grouporig, recnotif.extrarec.contoComOrig);
+
+ if (accountdestTable)
+ await accountdestTable.calcPending(false);
+ if (accountorigTable)
+ await accountorigTable.calcPending(true);
+
+ }
+ } catch (e) {
+ console.error(e);
+ }
+
+};
+
+
sendNotifSchema.statics.checkIfAlreadyExist = async function (idapp, tag, idpost, numtab) {
};
+
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
module.exports = { SendNotif: SendNotif };
diff --git a/src/server/models/site.js b/src/server/models/site.js
index beb7d47..70b2774 100755
--- a/src/server/models/site.js
+++ b/src/server/models/site.js
@@ -62,6 +62,12 @@ const SiteSchema = new Schema({
telegram_key_test: {
type: String,
},
+ teleg_cfg: {
+ type: String,
+ },
+ teleg_cfg_test: {
+ type: String,
+ },
telegram_bot_name_test: {
type: String,
},
@@ -226,6 +232,7 @@ module.exports.findAllIdApp = async function (idapp) {
rec.email_pwd = '';
rec.telegram_key = '';
rec.telegram_key_test = '';
+ rec.confsite = {};
return rec;
}
diff --git a/src/server/models/user.js b/src/server/models/user.js
index e1ecec9..208ce86 100755
--- a/src/server/models/user.js
+++ b/src/server/models/user.js
@@ -44,7 +44,7 @@ const UserSchema = new mongoose.Schema({
},
email: {
type: String,
- required: true,
+ // required: true,
trim: true,
minlength: 1,
unique: false,
@@ -2791,7 +2791,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
ris = true;
} else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
// Before to accept, I see if it's already set !
-
+
outres = {
cansend: false,
errormsg: '',
@@ -4826,6 +4826,7 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
try {
+ tools.startTimeLog('addExtraInfo')
if (version) {
let versattualeuser = 0;
@@ -4924,6 +4925,8 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
+ tools.endTimeLog('addExtraInfo')
+
return recUser;
} catch (e) {
@@ -5190,6 +5193,7 @@ UserSchema.statics.createNewSubRecord = async function (idapp, req) {
return rec;
};
+
const User = mongoose.model('User', UserSchema);
class Hero {
@@ -5204,6 +5208,45 @@ class Hero {
}
}
-module.exports = { User, Hero };
+const FuncUsers = {
+ createRegistration_withTelegram(userdata) {
+
+ const telegrambot = require('../telegram/telegrambot');
+
+ try {
+ // Cerca se esiste già
+ const user = new User(userdata);
+
+ user.verified_email = false;
+ user.lasttimeonline = new Date();
+ user.date_reg = new Date();
+
+ return user.save().then(async () => {
+ return User.findByUsername(user.idapp, user.username, false).
+ then(async (usertrovato) => {
+
+ const numutenti = await User.getNumUsers(user.idapp);
+
+ let msg = '++ Nuovo Entrato: [' + numutenti + '] ' + user.username + ' ' + user.name + ' ' + user.surname;
+
+ await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
+
+ return telegrambot.askConfirmationUser(user.idapp, shared_consts.CallFunz.REGISTRATION, user, '', '', '', '');
+ });
+ }).catch((e) => {
+ console.error(e.message);
+ });
+
+ } catch (e) {
+ console.error(e.message);
+ }
+
+ }
+};
+
+
+module.exports = {
+ User, Hero, FuncUsers
+};
diff --git a/src/server/populate/cities.js b/src/server/populate/cities.js
index c40eb69..db83ab3 100644
--- a/src/server/populate/cities.js
+++ b/src/server/populate/cities.js
@@ -89298,5 +89298,16 @@ module.exports = {
abitanti: '',
country: 'ONL',
},
+ {
+ _id: 8120,
+ istat: '',
+ comune: 'Italia',
+ prov: 'ITA',
+ reg: 'ITA',
+ pref: '',
+ cap: '',
+ abitanti: '',
+ country: 'ITA',
+ },
],
};
diff --git a/src/server/populate/provinces.js b/src/server/populate/provinces.js
index d8914d0..1552bf2 100644
--- a/src/server/populate/provinces.js
+++ b/src/server/populate/provinces.js
@@ -120,5 +120,6 @@ module.exports = {
{_id: 118, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud e Litorale', link_grp: 'https://t.me/c/1614195634/67?thread=43', link_telegram: ''},
{_id: 119, reg: 'PUG', prov: 'VAL', descr: 'Valle D\'Itria', link_grp: 'https://t.me/progettoriso/7016?thread=7015', link_telegram: ''},
{_id: 120, reg: 'SAR', prov: 'SUS', descr: 'Sud Sardegna', link_grp: 'https://t.me/c/1614195634/552?thread=545', link_telegram: ''},
+ {_id: 121, reg: 'ITA', prov: 'ITA', descr: 'Italia', link_grp: '', link_telegram: ''},
],
};
diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js
index 3f98910..8aed090 100755
--- a/src/server/router/index_router.js
+++ b/src/server/router/index_router.js
@@ -270,6 +270,7 @@ router.get('/test1', authenticate_noerror, async (req, res) => {
router.post('/settable', authenticate, async (req, res) => {
const params = req.body;
const mytable = globalTables.getTableByTableName(params.table);
+
let mydata = req.body.data;
let extrarec = {};
if (mydata && mydata.hasOwnProperty('extrarec')) {
@@ -277,6 +278,11 @@ router.post('/settable', authenticate, async (req, res) => {
delete mydata['extrarec'];
}
+ if (mydata === undefined) {
+ console.error('MYDATA VUOTO !');
+ return res.status(400).send('Mydata VUOTO');
+ }
+
const fieldsvalue = { 'ALL': 1 };
mydata.idapp = req.user.idapp;
@@ -483,12 +489,12 @@ router.post('/settable', authenticate, async (req, res) => {
groupnameDest = myrec ? myrec.groupname : '';
setnotif = true;
}
- if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
+ /*if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
circuitnameDest = myrec ? myrec.name : '';
setnotif = (myrec.visibility === 0); // Not send a notification to others if the Circuit is HIDDEN or PRIVATE
- }
+ }*/
}
if (setnotif) {
diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js
index 31abbe0..f5d0c9c 100755
--- a/src/server/router/users_router.js
+++ b/src/server/router/users_router.js
@@ -718,6 +718,9 @@ router.post('/updatesaldo', authenticate, async (req, res) => {
const username = req.user.username;
idapp = req.body.idapp;
locale = req.body.locale;
+ circuitId = req.body.circuitId;
+ groupname = req.body.groupname;
+ const lastdr = req.body['lastdr'] ? req.body['lastdr'] : '';
try {
const userprofile = await User.getExtraInfoByUsername(idapp, username);
@@ -725,6 +728,10 @@ router.post('/updatesaldo', authenticate, async (req, res) => {
userprofile
}
+ const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
+
+ ris.arrrecnotif = arrrecnotif;
+
return res.send({ ris });
} catch (e) {
@@ -1372,6 +1379,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
await Circuit.setstrProvByIdCityCircuits(idapp);
+ } else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') {
+
+ await Account.updateSaldoAndTransato_AllAccounts(idapp);
+
/*} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
@@ -1597,4 +1608,5 @@ router.post('/mgt', authenticate, async (req, res) => {
});
+
module.exports = router;
diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js
index 2c5c25f..a0f391f 100755
--- a/src/server/telegram/telegrambot.js
+++ b/src/server/telegram/telegrambot.js
@@ -3,14 +3,15 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.RISO];
-const appTelegram_DEVELOP = [tools.RISO];
+// const appTelegram_DEVELOP = [tools.RISO];
+const appTelegram_DEVELOP = [tools.FIOREDELLAVITA];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
const printf = require('util').format;
-const { User } = require('../models/user');
+const { User, FuncUsers } = require('../models/user');
const { MyGroup } = require('../models/mygroup');
const { Circuit } = require('../models/circuit');
const { CalZoom } = require('../models/calzoom');
@@ -1474,7 +1475,7 @@ class Telegram {
if (!riscreate) {
let rec = this.getRecInMem(msg);
if (!rec)
- rec = this.addUser(msg);
+ rec = await this.addUser(msg);
if (rec.user)
rec.status = Status.VERIFIED;
@@ -1601,9 +1602,14 @@ class Telegram {
}
}
+ let parse_mode = 'HTML';
+ let arr_bott_inline = []
+
if (risp === '') {
if (menusite) {
risp = await this.getValueMenu(this.idapp, rec, msg, testo, lang);
+ parse_mode = await this.getParseModeByMenu(this.idapp, rec, msg, testo, lang);
+ arr_bott_inline = await this.getArrBottInlineByMenu(this.idapp, rec, msg, testo, lang);
noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao ';
@@ -1762,7 +1768,7 @@ class Telegram {
if (contastiera) {
keyboard = {
- 'parse_mode': 'HTML',
+ 'parse_mode': parse_mode,
'reply_markup': {
'resize_keyboard': true,
'keyboard': await this.getKeyboard(id, undefined, this.getlang(msg)),
@@ -1771,6 +1777,12 @@ class Telegram {
}
+ let keyboard_inline = undefined;
+
+ if (arr_bott_inline.length > 0) {
+ keyboard_inline = cl.getInlineKeyboard(myuser.lang, arr_bott_inline);
+ }
+
if (rec.numdomande > 3 && rec.msgcodeprec === '') {
// if (rec.user) {
// const dashboard = await User.getDashboard(this.idapp, rec.user.aportador_solidario, rec.user.username, rec.user.aportador_solidario_name_surname);
@@ -1796,7 +1808,7 @@ class Telegram {
await tools.snooze(300);
risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp;
}
- this._inviaMsg(id, risp, keyboard);
+ this._inviaMsg(id, risp, keyboard, undefined, undefined, undefined, undefined, { parse_mode, keyboard_inline });
let strlog = 'USER [' + myname + ']: ' + testo + '\n';
@@ -2780,6 +2792,52 @@ class Telegram {
}
}
+ async addUserInDB_enteringInTelegramBot(msg) {
+
+ try {
+ // cerca se esiste già l'utente in Memoria
+ const rec = this.getRecInMem(msg);
+ if (!rec.user) {
+ // cerca se esiste già l'utente con il suo ID Telegram
+ const user = await User.UserByIdTelegram(this.idapp, msg.from.id);
+ if (!user) {
+ // Se non esiste già, creo la registrazione dell'Utente, senza password:
+ const myuserdata = {
+ idapp: this.idapp,
+ username: msg.from.username || msg.from.id,
+ name: msg.from.first_name || '',
+ lang: msg.from.language_code || 'it',
+ surname: msg.from.last_name || '',
+ profile: {
+ teleg_id: msg.from.id,
+ }
+ }
+
+ const recuser = await FuncUsers.createRegistration_withTelegram(myuserdata);
+ if (recuser) {
+ rec.user = recuser;
+ console.log(recuser.username, ' SI E\' VERIFICATO CON TELEGRAM !');
+ // let username = recuser.name;
+
+ /*if (!!msg.from.username) {
+ await MyTelegramBot.askConfirmationUser(this.idapp, shared_consts.CallFunz.REGISTRATION, recuser);
+ } else {
+ console.log(' ... MA GLI MANCA L\'USERNAME TELEGRAM !! ');
+ } */
+
+ }
+ }
+ }
+
+ return { ris: !!rec.user, recuser: rec.user };
+
+ } catch (e) {
+ console.error('Error addUserInDB_enteringInTelegramBot', e);
+ }
+
+ return { ris: false, recuser: null };
+ }
+
async sistemaRecDest(rec, msg) {
let recdest = this.getRecByUsername(rec.msgall_username_specifico);
if (!recdest) {
@@ -3267,7 +3325,7 @@ class Telegram {
let user = await User.UserByIdTelegram(this.idapp, id);
let rec = this.getRecInMem(msg);
if (user && !rec) {
- rec = this.addUser(msg);
+ rec = await this.addUser(msg);
}
if (rec) {
rec.user = user;
@@ -3289,7 +3347,7 @@ class Telegram {
}
}
- addUser(msg) {
+ async addUser(msg) {
const lang = this.getlang(msg);
const code = 100000 + Math.round(Math.random() * 899999);
@@ -3321,20 +3379,37 @@ class Telegram {
pageChange: false,
menuSaved: {},
pagenow: 1,
+ parse_mode: 'HTML',
menuDb: null,
aportador_solidario: '',
};
+ rec.status = Status.NONE;
+
if (!msg.from.username) {
- rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
+ if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskUsernameSulBot)) {
+ rec.status = Status.WAITFOR_USERNAME_TELEGRAM;
+ }
} else {
- rec.status = Status.WAITFOR_USERNAME_INVITANTE;
+ if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
+ rec.status = Status.WAITFOR_USERNAME_INVITANTE;
+ }
}
this.arrUsers.push(rec);
- // Aportador
- this.setInvitante(msg, this.getInvitanteByMsg(msg), false);
+ if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.AskInvitantesulBot)) {
+ // Aportador
+ this.setInvitante(msg, this.getInvitanteByMsg(msg), false);
+ }
+
+ if (tools.getConfSiteOptionEnabledByIdApp(this.idapp, shared_consts.ConfSite.registerUserWithBot)) {
+ const ris = await this.addUserInDB_enteringInTelegramBot(msg);
+ if (ris && ris.recuser) {
+ rec.recuser = ris.recuser;
+ rec.status = Status.VERIFIED;
+ }
+ }
return rec;
@@ -3388,13 +3463,13 @@ class Telegram {
for (const rec of recuser.menuDb) {
rec.active_mem = false;
+ const visibilita = (tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_ADMIN, isAdmin)
+ && tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_MANAGER, isManager)
+ && tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
+ || rec.visibility === 0;
+
if (rec.active && rec.page === recuser.pagenow
- && (tools.isBitAttivoESelez(rec.visibility,
- shared_consts.VISIB_ONLY_ADMIN, isAdmin) &&
- tools.isBitAttivoESelez(rec.visibility,
- shared_consts.VISIB_ONLY_MANAGER, isManager) &&
- tools.isBitAttivoESelez(rec.visibility,
- shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
+ && visibilita
) {
rec.active_mem = true;
if (true) {
@@ -3480,6 +3555,8 @@ class Telegram {
this.isMenu(recuser, msg, recdb.value, true);
return shared_consts.RIS_OK;
}
+ } else if (recdb.type === shared_consts.BOTTYPE_MARKDOWN) {
+ return recdb.value;
}
}
@@ -3493,6 +3570,59 @@ class Telegram {
}
+ async getParseModeByMenu(idapp, recuser, msg, testo, lang) {
+ try {
+ let parse_mode = 'HTML';
+ if (recuser) {
+
+ for (const recdb of recuser.menuDb) {
+ if (recdb.active_mem) {
+ if (recdb.idapp === idapp && recdb.lang === lang &&
+ recdb.label.toLowerCase() === testo) {
+ if (recdb.type === shared_consts.BOTTYPE_MARKDOWN) {
+ return 'Markdown'
+ } else {
+ return parse_mode;
+ }
+ }
+ }
+ }
+ }
+ return '';
+ } catch (e) {
+ return '';
+ }
+
+ }
+
+ async getArrBottInlineByMenu(idapp, recuser, msg, testo, lang) {
+ try {
+ let arr_bott_inline = [];
+ if (recuser) {
+
+ for (const recdb of recuser.menuDb) {
+ if (recdb.active_mem) {
+ if (recdb.idapp === idapp && recdb.lang === lang &&
+ recdb.label.toLowerCase() === testo) {
+ if (recdb.type === shared_consts.BOTTYPE_BOTTONI_INLINE) {
+ const jsonString = '[{"text": "primo", "callback_data": "1"}, {"text": "sec", "callback_data": "2"}]';
+ const jsonObject = JSON.parse(jsonString);
+
+ let myobj = JSON.parse(recdb.value);
+ arr_bott_inline.push(myobj);
+ }
+ }
+ }
+ }
+ }
+ return arr_bott_inline;
+ } catch (e) {
+ console.error(e);
+ return [];
+ }
+
+ }
+
async getKeyboard(id, menu, lang) {
let keyb = null;
@@ -3588,11 +3718,12 @@ class Telegram {
if (!form) {
form = {
- 'parse_mode': 'HTML',
+ 'parse_mode': opt && opt.parse_mode ? opt.parse_mode : 'HTML',
'message_id': msg_id,
'reply_markup': {
'resize_keyboard': true,
'keyboard': await this.getKeyboard(id, menu, mylang),
+ 'keyboard_inline': (opt && opt.keyboard_inline) ? opt.keyboard_inline : undefined,
},
};
}
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index 96990d1..1685098 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -417,7 +417,7 @@ module.exports = {
AYNI: '7',
CNM: '10',
RISO: '13',
- ARCADEI: '15',
+ FIOREDELLAVITA: '15',
HELP_CHAT: '',
TYPECONF_ZOOM: 'zoom',
@@ -1284,13 +1284,13 @@ module.exports = {
let ris = false;
let inviato = false;
+ let arrris = [];
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ || cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT || cmd ===
shared_consts.CIRCUITCMD.SENDCOINS_REFUSE) {
groupOrig = extrarec.grouporig
- let arrris = [];
let recnotif = null;
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
@@ -1370,6 +1370,19 @@ module.exports = {
}
}
+
+ if (inviato) {
+ if (arrris && arrris.length > 0) {
+ for (const notif of arrris) {
+ await SendNotif.updatePendingTransactions(notif);
+ }
+ } else {
+ if (ris) {
+ await SendNotif.updatePendingTransactions(ris.recnotif);
+ }
+ }
+ }
+
return { ris: ris.recnotif, inviato };
} catch (e) {
@@ -4206,7 +4219,7 @@ module.exports = {
getAhref(username, link) {
return `${username}`;
},
-
+
firstchars(value, numchars) {
if (!value) {
@@ -4282,7 +4295,7 @@ module.exports = {
newdescrtelegram += i18n.__('CONTRIB', contributo);
}
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
-
+
return { newdescr, newdescrtelegram }
} catch (e) {
console.error('Error', e);
diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js
index 2c46dbb..83d1ad4 100755
--- a/src/server/tools/shared_nodejs.js
+++ b/src/server/tools/shared_nodejs.js
@@ -259,6 +259,8 @@ module.exports = {
BOTTYPE_LINK: 2,
BOTTYPE_TEXT: 3,
BOTTYPE_MENU: 4,
+ BOTTYPE_MARKDOWN: 5,
+ BOTTYPE_BOTTONI_INLINE: 6,
RIS_OK: '👍🏻 OK',
@@ -357,6 +359,9 @@ module.exports = {
Notif_Reg_Bot_ToManagers: 1,
Notif_Reg_Push_Admin: 2,
Need_Aportador_On_DataReg_To_Verify_Reg: 4,
+ AskInvitantesulBot: 8,
+ AskUsernameSulBot: 16,
+ registerUserWithBot: 32,
},
MsgTeleg: {