- Transazioni Pendenti (all'Admin compaiono tutte quelle pendenti e con la possibilità di accettarle)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user