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;
|
||||
@@ -19,9 +22,9 @@ mongoose.plugin(schema => {
|
||||
const AccountSchema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString()
|
||||
}
|
||||
default: function() {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user