- Transazioni Pendenti (all'Admin compaiono tutte quelle pendenti e con la possibilità di accettarle)

This commit is contained in:
Surya Paolo
2024-09-29 23:26:37 +02:00
parent 5cca1ed2fa
commit 6289a2e2d2
12 changed files with 296 additions and 5 deletions

26
emails/risricevuti/it/html.pug Executable file
View File

@@ -0,0 +1,26 @@
p Ciao #{name},
p Hai ricevuto
strong #{qty} #{symbol}
| da parte di #{mittente} sul
strong #{nomecircuito} !
p <br>
p Apri #{nomeapp} per vedere il tuo nuovo saldo.
p <br>
p Cordiali Saluti
p Supporto #{nomeapp}
style(type="text/css").
html, body {
padding: 0;
margin: 0;
}
p {
margin: 4px; /* Imposta il margine a 0 per i paragrafi */
}
.grande {
font-size: 1.25rem;
font-weight: bold;
}

View File

@@ -0,0 +1 @@
=`Hai ricevuto ${qty} ${symbol} da ${mittente} sul ${nomecircuito}`

View File

@@ -256,4 +256,52 @@ TestTransazPao: 6.00 RIS]
Mer 18/09 ORE 15:43: [<b>Circuito RIS Rimini</b>]: Inviate Monete da marco.bi a TestTransazPao 2 RIS [causale: ]
Saldi:
marco.bi: -7.00 RIS]
TestTransazPao: 8.00 RIS]
TestTransazPao: 8.00 RIS]
Dom 29/09 ORE 17:32: [<b>Circuito RIS Bologna</b>]: Inviate Monete da Sincronicit4 a Didonemma 30 RIS [causale: Sistemazione per evento]
Saldi:
Sincronicit4: 70.00 RIS]
Didonemma: 58.00 RIS]
Dom 29/09 ORE 19:08: [<b>Circuito RIS Bologna</b>]: Inviate Monete da Sincronicit4 a Didonemma 60 RIS [causale: ]
Saldi:
Sincronicit4: 10.00 RIS]
Didonemma: 118.00 RIS]
Dom 29/09 ORE 19:10: [<b>Circuito RIS Bologna</b>]: Inviate Monete da pontiUmani (Anna50823) a Didonemma 15 RIS [causale: ]
Saldi:
pontiUmani (Anna50823): -364.00 RIS]
Didonemma: 133.00 RIS]
Dom 29/09 ORE 19:24: [<b>Circuito RIS Bologna</b>]: Inviate Monete da pontiUmani (Anna50823) a Didonemma 15 RIS [causale: ]
Saldi:
pontiUmani (Anna50823): -379.00 RIS]
Didonemma: 148.00 RIS]
Dom 29/09 ORE 23:10: [<b>Circuito RIS Bologna</b>]: Inviate Monete da pontiUmani (ElenaEspx) a Anna50823 3 RIS [causale: ]
Saldi:
pontiUmani (ElenaEspx): -382.00 RIS]
Anna50823: -84.00 RIS]
Dom 29/09 ORE 23:12: [<b>Circuito RIS Viterbo</b>]: Inviate Monete da L"ORTOINFESTACSAdiViterbo (Fulvio_F) a ArietteMorano 50 RIS [causale: Compenso prime 10 ore attività OrtoInfesta 2024]
Saldi:
L"ORTOINFESTACSAdiViterbo (Fulvio_F): 229.50 RIS]
ArietteMorano: 50.00 RIS]
Dom 29/09 ORE 23:17: [<b>Circuito RIS Bologna</b>]: Inviate Monete da nonsiemaisoli a Tonygraziano 21 RIS [causale: Da Natalia per libro. Grazie!!]
Saldi:
nonsiemaisoli: -33.50 RIS]
Tonygraziano: 93.00 RIS]
Dom 29/09 ORE 23:20: [<b>Circuito RIS Bologna</b>]: Inviate Monete da doulagiuliar a Tonygraziano 2 RIS [causale: Grazie Arcoiris per la tua arte]
Saldi:
doulagiuliar: -32.00 RIS]
Tonygraziano: 95.00 RIS]
Dom 29/09 ORE 23:21: [<b>Circuito RIS Bologna</b>]: Inviate Monete da SaraRiflePla a RosEle70 10 RIS [causale: Contributo gratitudine giro felice di vita]
Saldi:
SaraRiflePla: -30.00 RIS]
RosEle70: 10.00 RIS]
Dom 29/09 ORE 23:23: [<b>Circuito RIS Viterbo</b>]: Inviate Monete da sergiomazzanti a Annarosa 5 RIS [causale: ]
Saldi:
sergiomazzanti: -11.50 RIS]
Annarosa: -15.00 RIS]
Dom 29/09 ORE 23:24: [<b>Circuito RIS Italia</b>]: Inviate Monete da vasantayoga a BlediMakeru 25 RIS [causale: Consulenza legale]
Saldi:
vasantayoga: -25.00 RIS]
BlediMakeru: 25.00 RIS]
Dom 29/09 ORE 23:24: [<b>Circuito RIS Bologna</b>]: Inviate Monete da pontiUmani (Anna50823) a franz12090 15 RIS [causale: ]
Saldi:
pontiUmani (Anna50823): -397.00 RIS]
franz12090: 20.00 RIS]

View File

@@ -14,6 +14,7 @@ const { Account } = require('../models/account');
const { Province } = require('../models/province');
const shared_consts = require('../tools/shared_nodejs');
const i18n = require('i18n');
// Resolving error Unknown modifier: $pushAll
@@ -663,6 +664,8 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
const { User } = require('../models/user');
const sendemail = require('../sendemail');
let ris = {
result: false,
cansend: true,
@@ -766,6 +769,33 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
tools.sendMsgTelegramToAdmin(idapp, msg);
let mittente = orig;
try {
if (extrarec.dest) {
let myuserDest = await User.getUserByUsername(idapp, extrarec.dest);
// Invia una email al destinatario !
await sendemail.sendEmail_RisRicevuti(myuserDest.lang, myuserDest, myuserDest.email, idapp, { mittente, nomecircuito: circuittable.name, symbol: circuittable.symbol, qty: myqty });
} else if (extrarec.groupdest || extrarec.contoComDest) {
let arrusers = await MyGroup.getListAdminsByGroupName(idapp, groupDestoContoCom);
if (arrusers.length <= 0)
arrusers = await Circuit.getListAdminsByCircuitPath(idapp, groupDestoContoCom);
for (let i = 0; i < arrusers.length; i++) {
let myuserDest = await User.getUserByUsername(idapp, arrusers[i].username);
// Invia una email al destinatario !
await sendemail.sendEmail_RisRicevuti(myuserDest.lang, myuserDest, myuserDest.email, idapp, { mittente, nomecircuito: circuittable.name, symbol: circuittable.symbol, qty: myqty });
}
}
} catch (e) {
console.error('Err Email sendCoins', e);
}
} else {
// console.log('NON Inviate Monete da', usernameOrig, extrarec.grouporig, extrarec.dest, extrarec.groupdest, myqty, extrarec.causal);
}

View File

@@ -674,6 +674,34 @@ sendNotifSchema.statics.findLastNotifCoinsByUserIdAndIdApp = function (username,
};
sendNotifSchema.statics.findAllNotifCoinsAllIdAndIdApp = function (idapp) {
const SendNotif = this;
let filter = {
idapp,
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
status: 0,
'extrarec.circuitname': { $ne: "Circuito di TEST" },
'extrarec.symbol': { $ne: "RISTeST"},
}
return SendNotif.aggregate([
{
$match: filter,
},
{
$sort: { datenotif: -1 },
},
]).then(async (arrnotif) => {
return this.compileOtherFields(arrnotif);
}).catch((err) => {
console.error(err);
});
};
sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res, user) {
const SendNotif = this;
@@ -1248,6 +1276,40 @@ sendNotifSchema.statics.getSumPendingTransactionsDest = async function (idapp, u
};
sendNotifSchema.statics.RemovePendentTransactions = async function (idapp) {
const SendNodif = this;
return await SendNodif.deleteMany(
{
idapp,
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
status: 0,
}
);
};
sendNotifSchema.statics.RemoveOldNotif = async function (idapp, numgg) {
const SendNodif = this;
const currentDate = new Date();
const limitDate = new Date(currentDate.setDate(currentDate.getDate() - numgg));
return await SendNodif.deleteMany(
{
idapp,
date_created: { $lt: limitDate },
typedir: { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS },
}
);
};
sendNotifSchema.statics.RemoveOldNotif90 = async function (idapp) {
return this.RemoveOldNotif90(idapp, 90);
}
sendNotifSchema.statics.updatePendingTransactions = async function (recnotif) {
const { Circuit } = require('../models/circuit');

View File

@@ -3305,7 +3305,67 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
if (await User.isAdminByUsername(idapp, username_action)) {
outres.arrrecnotifcoins = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
}
}
} 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: '',
};
let outcheck = outres;
let risStatus = '';
const status = await SendNotif.getStatus(extrarec.notifId);
if (status === shared_consts.CircuitsNotif.STATUS_ACCEPTED) {
risStatus = i18n.__('STATUS_SENT');
} else if (status === shared_consts.CircuitsNotif.STATUS_REFUSED) {
risStatus = i18n.__('STATUS_REFUSED');
}
// if (!await SendNotif.checkIfCoinsAlreadySent(extrarec.notifId)) {
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
outcheck = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
} else {
outcheck.cansend = true;
outres.cansend = true;
}
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT && outcheck.cansend) {
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
outres = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
} else {
outcheck.cansend = false; //GIA INVIATO
}
}
if (outcheck.cansend) {
// Invia una notifica di moneta (accettata o rifiutata) alla persona
const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
if (outres && extrarec.groupname) {
// Setta agli altri admin,
}
}
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
if (await User.isAdminByUsername(idapp, username_action)) {
outres.arrrecnotifcoins = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
}
//----
} else {
outres.cansend = false;
@@ -4017,6 +4077,20 @@ UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) {
});
};
UserSchema.statics.isAdminByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({
idapp,
username,
}, { perm: 1 }).then((rec) => {
return User.isAdmin(rec.perm);
}).catch((e) => {
console.error('isAdminByUsername', e);
return false;
});
};
UserSchema.statics.getUsersList = function (idapp) {
const User = this;

View File

@@ -84,8 +84,13 @@ router.post('/load', authenticate, async (req, res) => {
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, false, '', data.path);
}
let arrrecnotifcoins = null;
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
const arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
if (isAdminById(req.user.id)) {
arrrecnotifcoins = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
}
/// E' QUIIII !!!!
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);

View File

@@ -1739,6 +1739,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
let last_notifs = null;
let last_notifcoins = null;
let usersList = null;
let last_notifcoins_inattesa = null;
// const sall = '0';
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
@@ -1751,7 +1752,12 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true);
// Se sono il Gestore, le ricevo tutte quante:
if (User.isAdmin(req.user.perm)) {
last_notifcoins_inattesa = SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true);
}
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
if (req.user) {

View File

@@ -159,7 +159,14 @@ async function getNotif(req, res) {
}
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
const arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: 0 }]);
let arrnotifcoins_inattesa = null;
if (await User.isAdminByUsername(idapp, req.user.username)) {
arrnotifcoins_inattesa = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
} else {
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: 0 }]);
}
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: {$ne: 0 }}]);

View File

@@ -1425,6 +1425,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
await Circuit.CheckTransazioniCircuiti(false);
} else if (mydata.dbop === 'CorreggiTransazioniCircuiti') {
await Circuit.CheckTransazioniCircuiti(true);
} else if (mydata.dbop === 'RemovePendentTransactions') {
await SendNotif.RemovePendentTransactions(true);
} else if (mydata.dbop === 'RemoveOldNotif90') {
await SendNotif.RemoveOldNotif90(idapp);
} else if (mydata.dbop === 'UpdateCoordProv') {
await Province.setCoordinatesOnDB();
} else if (mydata.dbop === 'insertGeojsonToMongoDB') {

View File

@@ -5,6 +5,8 @@ require('./config/config');
const Email = require('email-templates');
const { decode } = require('entities');
const i18n = require('i18n');
const { ObjectID } = require('mongodb');
@@ -302,6 +304,26 @@ module.exports = {
this.sendEmail_base('resetpwd/' + lang, emailto, mylocalsconf, '');
},
sendEmail_RisRicevuti: async function (lang, userDest, emailto, idapp, myrec) {
console.log('sendEmail_RisRicevuti');
let mylocalsconf = {
idapp,
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
emailto: emailto,
qty: myrec.qty,
mittente: decode(myrec.mittente),
nomecircuito: decode(myrec.nomecircuito),
symbol: myrec.symbol,
};
mylocalsconf = this.setParamsForTemplate(userDest, mylocalsconf);
this.sendEmail_base('risricevuti/' + lang, emailto, mylocalsconf, '');
},
sendEmail_Booking: async function (res, lang, emailto, user, idapp, recbooking) {
tools.mylog('sendEmail_Booking');

View File

@@ -5646,5 +5646,11 @@ module.exports = {
}
},
getLangByUsername(idapp, username) {
//++Todo LANG: Estrarre il Lang dall'username (user, group)
return 'it';
},
};