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
|
||||
*/
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
@@ -11,6 +12,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
@@ -20,8 +23,8 @@ const AccountSchema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
default: function() {
|
||||
return new ObjectID().toString()
|
||||
}
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -75,7 +78,7 @@ AccountSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
AccountSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
this._id = new ObjectID().toString()
|
||||
this._id = new ObjectID().toString();
|
||||
}
|
||||
|
||||
next();
|
||||
@@ -156,7 +159,6 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function(idapp, u
|
||||
else
|
||||
mycircuit = await Circuit.findOne({name: circuitName});
|
||||
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
|
||||
@@ -208,10 +210,49 @@ AccountSchema.statics.getUserAccounts = async function(idapp, username) {
|
||||
},
|
||||
},
|
||||
{$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);
|
||||
|
||||
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;
|
||||
} catch (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 arrUsernameReqCircuits = await MyCircuit.getUsernameReqCircuitsByCircuitname(idapp, username);
|
||||
|
||||
let listUserAccounts = await Account.getAccountsByUsername(idapp, username);
|
||||
|
||||
const manage_mycircuits = await Circuit.find({
|
||||
idapp,
|
||||
'admins': {
|
||||
@@ -318,7 +316,6 @@ CircuitSchema.statics.getCircuitsByUsername = async function(idapp, username, us
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
return {
|
||||
listUserAccounts,
|
||||
listcircuits,
|
||||
asked_circuits,
|
||||
refused_circuits,
|
||||
@@ -487,6 +484,7 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
||||
ris.cansend = false;
|
||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
||||
}
|
||||
|
||||
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
||||
ris.cansend = false;
|
||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
||||
|
||||
@@ -335,7 +335,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
|
||||
recnotif.paramsObj.username_action);
|
||||
tag = 'sendcoin';
|
||||
} 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);
|
||||
tag = 'sendcoin';
|
||||
} 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);
|
||||
|
||||
module.exports = {SendNotif: SendNotif};
|
||||
|
||||
@@ -2246,6 +2246,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
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 !
|
||||
|
||||
@@ -2284,9 +2285,9 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
||||
if (ris && username_action) {
|
||||
|
||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||
const user = await User.getExtraInfoByUsername(idapp, username_action);
|
||||
if (user) {
|
||||
outres.user = user;
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, username_action);
|
||||
if (userprofile) {
|
||||
outres.userprofile = userprofile;
|
||||
}
|
||||
outres.listcircuits = await Circuit.findAllIdApp(idapp);
|
||||
}
|
||||
@@ -3792,7 +3793,7 @@ UserSchema.statics.getExtraInfoByUsername = async function(idapp, username) {
|
||||
myuserextra = await User.addExtraInfo(idapp, myuser);
|
||||
}
|
||||
|
||||
return myuser._doc;
|
||||
return myuser._doc.profile;
|
||||
|
||||
};
|
||||
UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
||||
|
||||
@@ -781,6 +781,13 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
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 (camporequisiti) {
|
||||
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
||||
|
||||
@@ -128,9 +128,9 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
// setTimeout(() => {
|
||||
|
||||
//++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) => {
|
||||
console.log(e.message);
|
||||
|
||||
Reference in New Issue
Block a user