ver "0.5.9"
Saldo ora comprende anche le transazioni Pendenti (e le visualizza)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Account is a User's single Circuit
|
Account is a User's single Circuit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const mongoose = require('mongoose').set('debug', false);
|
const mongoose = require('mongoose').set('debug', false);
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
@@ -11,6 +12,8 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
const {ObjectID} = require('mongodb');
|
const {ObjectID} = require('mongodb');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin(schema => {
|
||||||
schema.options.usePushEach = true;
|
schema.options.usePushEach = true;
|
||||||
@@ -19,9 +22,9 @@ mongoose.plugin(schema => {
|
|||||||
const AccountSchema = new Schema({
|
const AccountSchema = new Schema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
default: function () {
|
default: function() {
|
||||||
return new ObjectID().toString()
|
return new ObjectID().toString();
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
idapp: {
|
idapp: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -75,7 +78,7 @@ AccountSchema.statics.findAllIdApp = async function(idapp) {
|
|||||||
|
|
||||||
AccountSchema.pre('save', async function(next) {
|
AccountSchema.pre('save', async function(next) {
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
this._id = new ObjectID().toString()
|
this._id = new ObjectID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
@@ -156,7 +159,6 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
|
|||||||
else
|
else
|
||||||
mycircuit = await Circuit.findOne({name: circuitName});
|
mycircuit = await Circuit.findOne({name: circuitName});
|
||||||
|
|
||||||
|
|
||||||
if (mycircuit) {
|
if (mycircuit) {
|
||||||
let myaccount = await Account.findOne(myquery);
|
let myaccount = await Account.findOne(myquery);
|
||||||
|
|
||||||
@@ -208,10 +210,49 @@ AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{$unwind: '$circuit'},
|
{$unwind: '$circuit'},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'sendnotifs',
|
||||||
|
as: 'notifspending',
|
||||||
|
let: {
|
||||||
|
circuitname: '$circuit.name',
|
||||||
|
username: '$username',
|
||||||
|
idapp: '$idapp',
|
||||||
|
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||||
|
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||||
|
},
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: {
|
||||||
|
$and: [
|
||||||
|
{$eq: ['$typedir', '$$typedir']},
|
||||||
|
{$eq: ['$typeid', '$$typeid']},
|
||||||
|
{$eq: ['$status', 0]},
|
||||||
|
{$eq: ['$sender', '$$username']},
|
||||||
|
{$eq: ['$idapp', '$$idapp']},
|
||||||
|
{$eq: ['$extrarec.circuitname', '$$circuitname']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
ris = await this.aggregate(aggr1);
|
ris = await this.aggregate(aggr1);
|
||||||
|
|
||||||
|
const {SendNotif} = require('../models/sendnotif');
|
||||||
|
|
||||||
|
if (ris) {
|
||||||
|
for (const account of ris) {
|
||||||
|
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||||
|
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||||
|
account.saldo -= saldopending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ris;
|
return ris;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('e', e);
|
console.error('e', e);
|
||||||
|
|||||||
@@ -278,8 +278,6 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, us
|
|||||||
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp, username);
|
// const arrUsernameCircuits = await User.getUsernameCircuitsByUsername(idapp, username);
|
||||||
// const arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
// const arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
||||||
|
|
||||||
let listUserAccounts = await Account.getAccountsByUsername(idapp, username);
|
|
||||||
|
|
||||||
const manage_mycircuits = await Circuit.find({
|
const manage_mycircuits = await Circuit.find({
|
||||||
idapp,
|
idapp,
|
||||||
'admins': {
|
'admins': {
|
||||||
@@ -318,7 +316,6 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, us
|
|||||||
}, whatToShow_Unknown).lean();
|
}, whatToShow_Unknown).lean();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listUserAccounts,
|
|
||||||
listcircuits,
|
listcircuits,
|
||||||
asked_circuits,
|
asked_circuits,
|
||||||
refused_circuits,
|
refused_circuits,
|
||||||
@@ -487,6 +484,7 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
|||||||
ris.cansend = false;
|
ris.cansend = false;
|
||||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
||||||
ris.cansend = false;
|
ris.cansend = false;
|
||||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ sendNotifSchema.statics.getRecNotif = function(id) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return SendNotif.findById(id).lean();
|
return SendNotif.findById(id).lean();
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
|||||||
recnotif.paramsObj.username_action);
|
recnotif.paramsObj.username_action);
|
||||||
tag = 'sendcoin';
|
tag = 'sendcoin';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED_SENT) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED_SENT) {
|
||||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
|
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', recnotif.paramsObj.extrarec.qty.toString(),
|
||||||
|
recnotif.paramsObj.extrarec.symbol,
|
||||||
recnotif.paramsObj.extrarec.dest);
|
recnotif.paramsObj.extrarec.dest);
|
||||||
tag = 'sendcoin';
|
tag = 'sendcoin';
|
||||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
|
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
|
||||||
@@ -832,6 +833,27 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendNotifSchema.statics.getSumPendingTransactions = async function(idapp, username, circuitname) {
|
||||||
|
const SendNotif = this;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const query = {
|
||||||
|
idapp,
|
||||||
|
sender: username,
|
||||||
|
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||||
|
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||||
|
status: 0,
|
||||||
|
'extrarec.circuitname': circuitname,
|
||||||
|
};
|
||||||
|
|
||||||
|
return await SendNotif.find(query).lean();
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('e', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
||||||
|
|
||||||
module.exports = {SendNotif: SendNotif};
|
module.exports = {SendNotif: SendNotif};
|
||||||
|
|||||||
@@ -2246,6 +2246,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
outres.cansend = false;
|
outres.cansend = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ris = true;
|
||||||
} else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
|
} else if ((cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT) || (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REFUSE)) {
|
||||||
// Before to accept, I see if it's already set !
|
// Before to accept, I see if it's already set !
|
||||||
|
|
||||||
@@ -2284,9 +2285,9 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
if (ris && username_action) {
|
if (ris && username_action) {
|
||||||
|
|
||||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||||
const user = await User.getExtraInfoByUsername(idapp, username_action);
|
const userprofile = await User.getExtraInfoByUsername(idapp, username_action);
|
||||||
if (user) {
|
if (userprofile) {
|
||||||
outres.user = user;
|
outres.userprofile = userprofile;
|
||||||
}
|
}
|
||||||
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
||||||
}
|
}
|
||||||
@@ -3792,7 +3793,7 @@ UserSchema.statics.getExtraInfoByUsername = async function(idapp, username) {
|
|||||||
myuserextra = await User.addExtraInfo(idapp, myuser);
|
myuserextra = await User.addExtraInfo(idapp, myuser);
|
||||||
}
|
}
|
||||||
|
|
||||||
return myuser._doc;
|
return myuser._doc.profile;
|
||||||
|
|
||||||
};
|
};
|
||||||
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||||
|
|||||||
@@ -781,6 +781,13 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
flotta.col_prima);
|
flotta.col_prima);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mydata.table === 'accounts') {
|
||||||
|
if ('saldo' in fieldsvalue) {
|
||||||
|
msg = 'l\'utente ' + req.user.username + ' ha variato il Saldo di ' + rec.username + ' a ' + fieldsvalue.saldo;
|
||||||
|
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mydata.table === 'users') {
|
if (mydata.table === 'users') {
|
||||||
if (camporequisiti) {
|
if (camporequisiti) {
|
||||||
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
||||||
|
|||||||
@@ -128,9 +128,9 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
|||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
|
|
||||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||||
const user = await User.getExtraInfoByUsername(idapp, req.user.username);
|
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||||
|
|
||||||
return res.send({arrnotif, user } );
|
return res.send({arrnotif, userprofile } );
|
||||||
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user