- fixed: Se tenti d'inviare dei RIS a chi ha raggiunto il limite, deve comparirti un msg ed inviare un msg al destinatario !
This commit is contained in:
@@ -3023,6 +3023,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
// console.log('setCircuitCmd', cmd);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
let ris = null;
|
||||
let outres = {
|
||||
@@ -3261,73 +3262,86 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
outres = await Circuit.sendCoins(onlycheck, idapp, usernameOrig, extrarec);
|
||||
|
||||
if (outres.cansend) {
|
||||
// Invia una notifica di moneta alla persona
|
||||
//const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action,
|
||||
// extrarec);
|
||||
//if (out)
|
||||
// outres.result = out.ris;
|
||||
} else {
|
||||
outres.cansend = false;
|
||||
}
|
||||
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 !
|
||||
|
||||
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: '',
|
||||
}; */
|
||||
|
||||
/*outres = {
|
||||
cansend: false,
|
||||
errormsg: '',
|
||||
}; */
|
||||
let outcheck = outres;
|
||||
|
||||
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 (true) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||
//outcheck = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
|
||||
outcheck.cansend = true;
|
||||
outres.cansend = true;
|
||||
} else {
|
||||
outcheck.cansend = true;
|
||||
outres.cansend = true;
|
||||
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');
|
||||
}
|
||||
|
||||
cmd = shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT;
|
||||
|
||||
/*if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT && outcheck.cansend) {
|
||||
if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
||||
outres = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||
|
||||
// if (!await SendNotif.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
||||
//if (!await Movement.checkIfCoinsAlreadySent(extrarec.notifId)) {
|
||||
if (true) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||
//outcheck = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
|
||||
outcheck.cansend = true;
|
||||
outres.cansend = true;
|
||||
} else {
|
||||
outcheck.cansend = false; //GIA INVIATO
|
||||
outcheck.cansend = true;
|
||||
outres.cansend = true;
|
||||
}
|
||||
} */
|
||||
|
||||
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);
|
||||
cmd = shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT;
|
||||
|
||||
if (outres && extrarec.groupname) {
|
||||
// Setta agli altri admin,
|
||||
/*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, shared_consts.QualiNotifs.OTHERS);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (outres.errormsg) {
|
||||
let msgerr = '';
|
||||
let username_dest = extrarec.dest;
|
||||
if (outres.errorcode === shared_consts.SENDRIS_CODES.EXCEED_FIDO) {
|
||||
} else if (outres.errorcode === shared_consts.SENDRIS_CODES.EXCEED_QTAMAX) {
|
||||
// invia un messaggio al destinatario
|
||||
const msgDest = i18n.__('EXCEED_QTAMAX', usernameOrig, extrarec.qty.toString(), extrarec.circuitname);
|
||||
await telegrambot.sendMsgTelegram(idapp, username_dest, msgDest);
|
||||
|
||||
msgerr = i18n.__('EXCEED_QTAMAX_MITTENTE', username_dest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
}
|
||||
|
||||
console.warn('🔴 ATTENZIONE! ', outres.errormsg + '\n(Mittente: ' + usernameOrig + ')');
|
||||
// await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
|
||||
|
||||
// Invia questo msg anche all'Admin
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, outres.errormsg + '\n(Mittente: ' + usernameOrig + ')', true);
|
||||
|
||||
}
|
||||
|
||||
} else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
|
||||
|
||||
Reference in New Issue
Block a user