- 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

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;