correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...

This commit is contained in:
Surya Paolo
2023-10-01 01:24:47 +02:00
parent 142dcadca9
commit b6579832b6
27 changed files with 8952 additions and 8875 deletions

View File

@@ -141,7 +141,7 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
{ $group: { _id: null, count: { $sum: '$saldo' } } }
];
ris = await Account.aggregate(aggr1);
const ris = await Account.aggregate(aggr1);
return ris ? ris[0].count : 0;
@@ -340,6 +340,7 @@ AccountSchema.statics.createAccount = async function (idapp, username, circuitNa
};
AccountSchema.statics.getUserAccounts = async function (idapp, username) {
const { SendNotif } = require('../models/sendnotif');
try {
let aggr1 = [
@@ -391,17 +392,25 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
},
];
ris = await this.aggregate(aggr1);
const ris = await this.aggregate(aggr1);
const { SendNotif } = require('../models/sendnotif');
// console.log('1 - INIZIA getUserAccounts ')
// console.log(aggr1);
if (ris) {
for (const account of ris) {
try {
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
account.saldo -= saldopending;
account.totTransato = account.totTransato || 0;
//++OTTIMIZZARE QUESTA PARTE ! (CON UNA QUERY...)
// console.log(' 1B - PENDIND... ')
let pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
let saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
if (saldopending !== 0) {
account.saldo -= saldopending;
account.totTransato = account.totTransato || 0;
}
} catch (e) {
console.error('getUserAccounts 1) ', e);
}
@@ -409,6 +418,7 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
}
}
// console.log(' 2 - FINE getUserAccounts LEN=', ris.length)
return ris;
} catch (e) {
console.error('getUserAccounts', e);
@@ -470,16 +480,20 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
},
];
ris = await this.aggregate(aggr1);
const ris = await this.aggregate(aggr1);
const { SendNotif } = require('../models/sendnotif');
if (ris) {
// tools.startTimeLog('Query Pending')
for (const account of ris) {
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.result.extrarec.qty, 0);
account.saldo -= saldopending;
if (saldopending) {
account.saldo -= saldopending;
}
}
// tools.endTimeLog('Query Pending')
}
return ris;
@@ -493,7 +507,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valmax) {
const Account = this;
ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
const ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
{
$set:
{
@@ -508,7 +522,7 @@ AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valma
AccountSchema.statics.SetMinMaxComunitari = async function (idapp, valmin, valmax) {
const Account = this;
ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
const ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
{
$set:
{
@@ -524,7 +538,7 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
const Account = this;
if (circuitId) {
ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
const ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
{
$set:
{
@@ -533,7 +547,7 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax
}
});
} else {
ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
const ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
{
$set:
{
@@ -556,12 +570,12 @@ AccountSchema.statics.updateFido = async function (idapp, username, circuitId, f
};
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
const account = await Account.findOne({_id: id}).lean();
const account = await Account.findOne({ _id: id }).lean();
const { Circuit } = require('../models/circuit');
if (account) {
const circuit = await Circuit.findOne({_id: account.circuitId}).lean();
const circuit = await Circuit.findOne({ _id: account.circuitId }).lean();
if (circuit) {
return circuit.admins.findIndex((admin) => admin.username === username) >= 0;
}