Visu Sent Monete
This commit is contained in:
@@ -455,6 +455,8 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
let ris = {
|
||||
cansend: true,
|
||||
errormsg: '',
|
||||
rec: null,
|
||||
useraccounts: [],
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -471,7 +473,7 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
const accountorig = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, { circuitId: reccircuit._id }, true);
|
||||
|
||||
// Check if Sender has enough money
|
||||
if (accountorig.saldo - myqty < accountorig.fidoConcesso) {
|
||||
if (accountorig.saldo - myqty < -accountorig.fidoConcesso) {
|
||||
ris.cansend = false;
|
||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO');
|
||||
}
|
||||
@@ -482,7 +484,9 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
|
||||
if (!onlycheck) {
|
||||
// Add a Transaction !
|
||||
ris.cansend = await Movement.addMov(idapp, accountorig, accountdest, myqty, extrarec.causal);
|
||||
ris.rec = await Movement.addMov(idapp, accountorig, accountdest, myqty, extrarec.causal);
|
||||
|
||||
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
||||
|
||||
if (ris.cansend) {
|
||||
console.log('Invia Monete da', usernameOrig, extrarec.dest, extrarec.qty, extrarec.causal);
|
||||
|
||||
@@ -114,6 +114,17 @@ sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
|
||||
}
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getRecNotif = function(id) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
return SendNotif.findById(id).lean();
|
||||
}catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, lastdataread, idapp) {
|
||||
const SendNotif = this;
|
||||
|
||||
@@ -259,7 +270,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.username_action);
|
||||
recnotif.openUrl = '/my/' + userorig;
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_ACCEPTED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
|
||||
@@ -286,7 +298,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
}
|
||||
tag = 'refcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.singleadmin_username);
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
tag = 'reqcircuits';
|
||||
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||
@@ -309,11 +322,13 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
}
|
||||
tag = 'removeadmincircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty.toString(),
|
||||
recnotif.paramsObj.extrarec.symbol);
|
||||
tag = 'sendcoin';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.username_action);
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
|
||||
recnotif.paramsObj.username_action);
|
||||
tag = 'sendcoin';
|
||||
}
|
||||
}
|
||||
@@ -402,7 +417,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
|
||||
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return null;
|
||||
}
|
||||
@@ -423,6 +438,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
}
|
||||
|
||||
let newstatus = 0;
|
||||
let idnotiftosearch = '';
|
||||
let typeidsearch = 0;
|
||||
let dest = '';
|
||||
|
||||
@@ -453,6 +469,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_DELETED;
|
||||
}
|
||||
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifId;
|
||||
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
dest = myrecnotif.dest;
|
||||
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
@@ -483,7 +500,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
descr: myrecnotif.descr,
|
||||
};
|
||||
|
||||
const query = {
|
||||
let query = {
|
||||
idapp: myrecnotif.idapp,
|
||||
typedir: myrecnotif.typedir,
|
||||
typeid: typeidsearch,
|
||||
@@ -492,6 +509,13 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
status: 0,
|
||||
};
|
||||
|
||||
if (idnotiftosearch) {
|
||||
query = {
|
||||
_id: idnotiftosearch,
|
||||
status: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Cerca il record e se lo trova lo aggiorna
|
||||
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
|
||||
new: true,
|
||||
@@ -516,11 +540,43 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getStatus = async function(notifId) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
return await SendNotif.findOne({_id: notifId}, {status: 1}).lean().then((rec) => rec.status);
|
||||
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
const status = await SendNotif.getStatus(notifId);
|
||||
|
||||
if (status !== null) {
|
||||
return (status === shared_consts.CircuitsNotif.STATUS_ACCEPTED) ||
|
||||
(status === shared_consts.CircuitsNotif.STATUS_REFUSED);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} catch (e) {
|
||||
// If Error, don't send the coins
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
|
||||
|
||||
const SendNotif = this;
|
||||
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
|
||||
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
|
||||
if (!myrecout)
|
||||
return null;
|
||||
|
||||
@@ -734,7 +790,9 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
|
||||
try {
|
||||
|
||||
myrecnotif.dest = myrecnotif.paramsObj && myrecnotif.paramsObj.usernameDest ? myrecnotif.paramsObj.usernameDest : '';
|
||||
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked ? myrecnotif.paramsObj.username_worked : myrecnotif.dest;
|
||||
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked
|
||||
? myrecnotif.paramsObj.username_worked
|
||||
: myrecnotif.dest;
|
||||
|
||||
if (onlysave) {
|
||||
await SendNotif.saveNotif(myrecnotif);
|
||||
|
||||
@@ -2081,6 +2081,8 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD
|
||||
|
||||
UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
|
||||
let ris = null;
|
||||
let update = {};
|
||||
try {
|
||||
@@ -2197,28 +2199,52 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
ris = await Circuit.removeAdminOfCircuit(idapp, usernameOrig, circuitname); // Rimuovo la richiesta di entrare nel gruppo
|
||||
w
|
||||
|
||||
// Invia una notifica alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
|
||||
let ris = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
|
||||
if (ris.cansend) {
|
||||
let ris2 = await Circuit.sendCoins(true, idapp, usernameOrig, extrarec);
|
||||
if (ris2.cansend) {
|
||||
// Invia una notifica di moneta alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
} else {
|
||||
ris.cansend = false;
|
||||
ris2.cansend = false;
|
||||
}
|
||||
|
||||
ris = ris2;
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) {
|
||||
ris = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||
// Before to accept, I see if it's already set !
|
||||
|
||||
if (ris.cansend) {
|
||||
// Invia una notifica di moneta alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
let ris2 = {
|
||||
cansend: false,
|
||||
errormsg: '',
|
||||
};
|
||||
|
||||
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)) {
|
||||
ris2 = await Circuit.sendCoins(false, idapp, usernameOrig, extrarec);
|
||||
|
||||
if (ris2.cansend) {
|
||||
// Invia una notifica di moneta alla persona
|
||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||
}
|
||||
|
||||
ris2.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
||||
} else {
|
||||
ris2.cansend = false;
|
||||
|
||||
ris2.errormsg = i18n.__('CIRCUIT_COINS_ALREADY_PROCESSED', risStatus);
|
||||
}
|
||||
ris = ris2;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error setCircuitCmd: ', e);
|
||||
|
||||
Reference in New Issue
Block a user