fix TotCircolante

This commit is contained in:
Paolo Arena
2022-09-19 15:10:23 +02:00
parent c19fb44ffb
commit 3c550595f0
2 changed files with 22 additions and 1 deletions

View File

@@ -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) {
const account = this;