fix TotCircolante
This commit is contained in:
@@ -114,6 +114,26 @@ AccountSchema.statics.getAccountsByUsername = async function(idapp, username) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AccountSchema.statics.calcTotCircolante = async function(idapp, circuitId) {
|
||||||
|
const Account = this;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let aggr1 = [
|
||||||
|
{
|
||||||
|
$match: {idapp, circuitId, saldo: {$gt: 0}},
|
||||||
|
},
|
||||||
|
{ $group: { _id: null, count: { $sum: '$saldo' } } }
|
||||||
|
];
|
||||||
|
|
||||||
|
ris = await Account.aggregate(aggr1);
|
||||||
|
|
||||||
|
return ris ? ris[0].count : 0;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('err', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
AccountSchema.methods.addtoSaldo = async function(amount) {
|
AccountSchema.methods.addtoSaldo = async function(amount) {
|
||||||
const account = this;
|
const account = this;
|
||||||
|
|
||||||
|
|||||||
@@ -526,7 +526,8 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
|||||||
|
|
||||||
// Somma di tutte le transazioni
|
// Somma di tutte le transazioni
|
||||||
circuittable.totTransato += myqty;
|
circuittable.totTransato += myqty;
|
||||||
circuittable.totCircolante = circuittable.totCircolante + (circolanteAtt - circolantePrec);
|
// circuittable.totCircolante = circuittable.totCircolante + (circolanteAtt - circolantePrec);
|
||||||
|
circuittable.totCircolante = await Account.calcTotCircolante(idapp, circuittable._id);
|
||||||
await circuittable.save();
|
await circuittable.save();
|
||||||
|
|
||||||
ris.result = true;
|
ris.result = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user