- versione: 1.2.77
- aggiustamenti e miglioramenti estetici
This commit is contained in:
@@ -488,7 +488,8 @@ CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, u
|
|||||||
{ deleted: { $exists: true, $eq: false } }],
|
{ deleted: { $exists: true, $eq: false } }],
|
||||||
}, whatToShow_Unknown).sort({ status: -1 }).lean();
|
}, whatToShow_Unknown).sort({ status: -1 }).lean();
|
||||||
|
|
||||||
const last_my_transactions = await Movement.getLastN_Transactions(idapp, nummovTodownload, username, '');
|
const last_my_transactions = await Movement.getLastN_Transactions(idapp, nummovTodownload, nummovTodownload, username, '');
|
||||||
|
const total_transactions = await Movement.getNumTotalTransactions(idapp, username, '');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listcircuits,
|
listcircuits,
|
||||||
@@ -497,6 +498,7 @@ CircuitSchema.statics.getCircuitsByUsername = async function (idapp, username, u
|
|||||||
manage_mycircuits,
|
manage_mycircuits,
|
||||||
mycircuits: user.profile.mycircuits,
|
mycircuits: user.profile.mycircuits,
|
||||||
last_my_transactions,
|
last_my_transactions,
|
||||||
|
total_transactions
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const { ObjectId } = require('mongodb');
|
|||||||
const { Account } = require('../models/account');
|
const { Account } = require('../models/account');
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin((schema) => {
|
||||||
schema.options.usePushEach = true;
|
schema.options.usePushEach = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,12 +73,10 @@ MovementSchema.statics.findAllIdApp = async function (idapp) {
|
|||||||
const myfind = { idapp };
|
const myfind = { idapp };
|
||||||
|
|
||||||
return await tools.findAllQueryIdApp(MyMovement, myfind);
|
return await tools.findAllQueryIdApp(MyMovement, myfind);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.pre('save', async function (next) {
|
MovementSchema.pre('save', async function (next) {
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
|
|
||||||
this.transactionDate = new Date();
|
this.transactionDate = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +88,6 @@ MovementSchema.statics.getFieldsForSearch = function () {
|
|||||||
{ field: 'causal', type: tools.FieldType.string },
|
{ field: 'causal', type: tools.FieldType.string },
|
||||||
{ field: 'amount', type: tools.FieldType.number },
|
{ field: 'amount', type: tools.FieldType.number },
|
||||||
];
|
];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.executeQueryTable = function (idapp, params) {
|
MovementSchema.statics.executeQueryTable = function (idapp, params) {
|
||||||
@@ -98,14 +95,21 @@ MovementSchema.statics.executeQueryTable = function (idapp, params) {
|
|||||||
return tools.executeQueryTable(this, 0, params);
|
return tools.executeQueryTable(this, 0, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accountToIdTable, amount, causal, causalDest, notifId, idOrdersCart) {
|
MovementSchema.statics.addMov = async function (
|
||||||
|
idapp,
|
||||||
|
accountFromIdTable,
|
||||||
|
accountToIdTable,
|
||||||
|
amount,
|
||||||
|
causal,
|
||||||
|
causalDest,
|
||||||
|
notifId,
|
||||||
|
idOrdersCart
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
// Only positive values
|
// Only positive values
|
||||||
amount = Math.abs(amount);
|
amount = Math.abs(amount);
|
||||||
|
|
||||||
let mymov = await Movement.create(
|
let mymov = await Movement.create({
|
||||||
{
|
|
||||||
idapp,
|
idapp,
|
||||||
transactionDate: new Date(),
|
transactionDate: new Date(),
|
||||||
accountFromId: accountFromIdTable._id,
|
accountFromId: accountFromIdTable._id,
|
||||||
@@ -117,8 +121,7 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
|||||||
residual: 0,
|
residual: 0,
|
||||||
notifId,
|
notifId,
|
||||||
// expiringDate:
|
// expiringDate:
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if (mymov) {
|
if (mymov) {
|
||||||
// Update saldo dell'Account
|
// Update saldo dell'Account
|
||||||
@@ -134,24 +137,26 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
|||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username, groupname, contocom, circuitId) {
|
MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username, groupname, contocom, circuitId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!circuitId) {
|
if (!circuitId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, true, groupname, contocom);
|
const myaccount = await Account.getAccountByUsernameAndCircuitId(
|
||||||
|
idapp,
|
||||||
|
username,
|
||||||
|
circuitId,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
groupname,
|
||||||
|
contocom
|
||||||
|
);
|
||||||
|
|
||||||
if (myaccount) {
|
if (myaccount) {
|
||||||
|
|
||||||
let aggr1 = [
|
let aggr1 = [
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
idapp,
|
idapp,
|
||||||
$or: [
|
$or: [{ accountFromId: myaccount._id }, { accountToId: myaccount._id }],
|
||||||
{ accountFromId: myaccount._id },
|
|
||||||
{ accountToId: myaccount._id }],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -169,15 +174,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -197,15 +196,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -226,15 +219,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -285,15 +272,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -313,15 +294,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -341,15 +316,9 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -364,8 +333,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project:
|
$project: {
|
||||||
{
|
|
||||||
transactionDate: 1,
|
transactionDate: 1,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
causal: 1,
|
causal: 1,
|
||||||
@@ -393,12 +361,10 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
'contocomto.name': 1,
|
'contocomto.name': 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return aggr1;
|
return aggr1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -406,9 +372,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
|||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp, circuitId) {
|
MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp, circuitId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!circuitId) {
|
if (!circuitId) {
|
||||||
return [];
|
return [];
|
||||||
@@ -434,15 +398,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -462,15 +420,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -490,15 +442,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -530,11 +476,11 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
$match: { 'accto.circuitId': circuitId },
|
$match: { 'accto.circuitId': circuitId },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'circuits',
|
from: 'circuits',
|
||||||
'localField': 'accfrom.circuitId',
|
localField: 'accfrom.circuitId',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'circuitfrom',
|
as: 'circuitfrom',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -544,11 +490,11 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'circuits',
|
from: 'circuits',
|
||||||
'localField': 'accto.circuitId',
|
localField: 'accto.circuitId',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'circuitto',
|
as: 'circuitto',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -563,15 +509,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -591,15 +531,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -619,15 +553,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -642,8 +570,7 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project:
|
$project: {
|
||||||
{
|
|
||||||
transactionDate: 1,
|
transactionDate: 1,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
causal: 1,
|
causal: 1,
|
||||||
@@ -667,11 +594,9 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
'contocomto.title': 1,
|
'contocomto.title': 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return aggr1;
|
return aggr1;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -682,13 +607,11 @@ MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function (idapp,
|
|||||||
MovementSchema.statics.getTotal_Transactions = async function (idapp) {
|
MovementSchema.statics.getTotal_Transactions = async function (idapp) {
|
||||||
const MyMovement = this;
|
const MyMovement = this;
|
||||||
|
|
||||||
const numtransac = await MyMovement.countDocuments(
|
const numtransac = await MyMovement.countDocuments({
|
||||||
{
|
|
||||||
idapp,
|
idapp,
|
||||||
});
|
});
|
||||||
|
|
||||||
return numtransac;
|
return numtransac;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.getTot_RIS_Transati = async function (idapp) {
|
MovementSchema.statics.getTot_RIS_Transati = async function (idapp) {
|
||||||
@@ -697,19 +620,19 @@ MovementSchema.statics.getTot_RIS_Transati = async function (idapp) {
|
|||||||
// Utilizza l'aggregazione per sommare tutti gli 'amount' per un dato 'idapp'
|
// Utilizza l'aggregazione per sommare tutti gli 'amount' per un dato 'idapp'
|
||||||
const numtot = await MyMovement.aggregate([
|
const numtot = await MyMovement.aggregate([
|
||||||
{
|
{
|
||||||
$match: { idapp } // Filtra i documenti per 'idapp'
|
$match: { idapp }, // Filtra i documenti per 'idapp'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$sort: {
|
$sort: {
|
||||||
transactionDate: -1,
|
transactionDate: -1,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: null,
|
_id: null,
|
||||||
totalAmount: { $sum: "$amount" } // Somma tutti gli 'amount'
|
totalAmount: { $sum: '$amount' }, // Somma tutti gli 'amount'
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -717,8 +640,6 @@ MovementSchema.statics.getTot_RIS_Transati = async function (idapp) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.getMovsByCircuitId = async function (idapp, username, circuitId) {
|
MovementSchema.statics.getMovsByCircuitId = async function (idapp, username, circuitId) {
|
||||||
@@ -741,56 +662,28 @@ MovementSchema.statics.checkIfCoinsAlreadySent = async function (notifId) {
|
|||||||
try {
|
try {
|
||||||
const rec = await MyMovement.findOne({ notifId }, { _id: 1 });
|
const rec = await MyMovement.findOne({ notifId }, { _id: 1 });
|
||||||
return !!rec;
|
return !!rec;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If Error, don't send the coins
|
// If Error, don't send the coins
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz = 10, username = '', groupname = '', contocom = '') {
|
MovementSchema.statics.getNumTotalTransactions = async function (idapp, username = '', groupname = '', contocom = '') {
|
||||||
const MyMovement = this;
|
const MyMovement = this;
|
||||||
|
|
||||||
// get last "numtransaz" transactions
|
// Determina se filtrare per un account specifico
|
||||||
|
|
||||||
let abilitaquerypersingolo = (username || groupname || contocom);
|
let abilitaquerypersingolo = (username || groupname || contocom);
|
||||||
|
|
||||||
let querym2 = null;
|
if (!abilitaquerypersingolo) {
|
||||||
|
// Se non c'è filtro, conta tutte le transazioni dell'app
|
||||||
if (abilitaquerypersingolo) {
|
return await MyMovement.countDocuments({ idapp });
|
||||||
let v1 = [];
|
|
||||||
|
|
||||||
if (username) {
|
|
||||||
v1.push({ 'userfrom.username': username },
|
|
||||||
{ 'userto.username': username });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupname) {
|
// Pipeline per contare le transazioni
|
||||||
v1.push({ 'groupfrom.groupname': groupname },
|
let pipeline = [
|
||||||
{ 'groupto.groupname': groupname });
|
|
||||||
}
|
|
||||||
if (contocom) {
|
|
||||||
v1.push({ 'contocomfrom.name': contocom },
|
|
||||||
{ 'contocomto.name': contocom });
|
|
||||||
}
|
|
||||||
|
|
||||||
querym2 = {
|
|
||||||
$match:
|
|
||||||
{ $or: v1 }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
let aggr1 = [
|
|
||||||
{
|
{
|
||||||
$match: { idapp },
|
$match: { idapp },
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$sort: {
|
|
||||||
transactionDate: -1,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'accounts',
|
from: 'accounts',
|
||||||
@@ -800,21 +693,168 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $unwind: '$accfrom' },
|
{ $unwind: '$accfrom' },
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'accounts',
|
||||||
|
localField: 'accountToId',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'accto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: '$accto' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Costruisci il filtro OR per entrata o uscita
|
||||||
|
let orConditions = [];
|
||||||
|
|
||||||
|
if (username) {
|
||||||
|
orConditions.push(
|
||||||
|
{ 'accfrom.username': username },
|
||||||
|
{ 'accto.username': username }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupname) {
|
||||||
|
orConditions.push(
|
||||||
|
{ 'accfrom.groupname': groupname },
|
||||||
|
{ 'accto.groupname': groupname }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contocom) {
|
||||||
|
orConditions.push(
|
||||||
|
{ 'accfrom.contocom': contocom },
|
||||||
|
{ 'accto.contocom': contocom }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiungi il match con OR
|
||||||
|
pipeline.push({
|
||||||
|
$match: {
|
||||||
|
$or: orConditions
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Conta i documenti
|
||||||
|
pipeline.push({
|
||||||
|
$count: 'total'
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await MyMovement.aggregate(pipeline);
|
||||||
|
|
||||||
|
// Se non ci sono risultati, ritorna 0
|
||||||
|
return result.length > 0 ? result[0].total : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
MovementSchema.statics.getLastN_Transactions = async function (
|
||||||
|
idapp,
|
||||||
|
numtransaz = 10,
|
||||||
|
numtransaz_uscita = 10,
|
||||||
|
username = '',
|
||||||
|
groupname = '',
|
||||||
|
contocom = ''
|
||||||
|
) {
|
||||||
|
const MyMovement = this;
|
||||||
|
|
||||||
|
// Determina se filtrare per un account specifico
|
||||||
|
let abilitaquerypersingolo = username || groupname || contocom;
|
||||||
|
|
||||||
|
// Costruisce i criteri di filtro base per identificare l'account
|
||||||
|
let matchCriteria = {};
|
||||||
|
if (username) {
|
||||||
|
matchCriteria['accfrom.username'] = username;
|
||||||
|
matchCriteria['accto.username'] = username;
|
||||||
|
}
|
||||||
|
if (groupname) {
|
||||||
|
matchCriteria['accfrom.groupname'] = groupname;
|
||||||
|
matchCriteria['accto.groupname'] = groupname;
|
||||||
|
}
|
||||||
|
if (contocom) {
|
||||||
|
matchCriteria['accfrom.contocom'] = contocom;
|
||||||
|
matchCriteria['accto.contocom'] = contocom;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pipeline comune per i lookup
|
||||||
|
const commonLookups = [
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'accounts',
|
||||||
|
localField: 'accountFromId',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'accfrom',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: '$accfrom' },
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: 'accounts',
|
||||||
|
localField: 'accountToId',
|
||||||
|
foreignField: '_id',
|
||||||
|
as: 'accto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $unwind: '$accto' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Funzione helper per costruire la pipeline completa
|
||||||
|
const buildPipeline = (isEntrata) => {
|
||||||
|
let pipeline = [
|
||||||
|
{
|
||||||
|
$match: { idapp },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: {
|
||||||
|
transactionDate: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...commonLookups,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Filtro per entrata/uscita
|
||||||
|
if (abilitaquerypersingolo) {
|
||||||
|
let matchCondition = {};
|
||||||
|
|
||||||
|
if (username) {
|
||||||
|
matchCondition['username'] = isEntrata ? 'accto.username' : 'accfrom.username';
|
||||||
|
pipeline.push({
|
||||||
|
$match: {
|
||||||
|
[matchCondition['username']]: username,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (groupname) {
|
||||||
|
matchCondition['groupname'] = isEntrata ? 'accto.groupname' : 'accfrom.groupname';
|
||||||
|
pipeline.push({
|
||||||
|
$match: {
|
||||||
|
[matchCondition['groupname']]: groupname,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (contocom) {
|
||||||
|
matchCondition['contocom'] = isEntrata ? 'accto.contocom' : 'accfrom.contocom';
|
||||||
|
pipeline.push({
|
||||||
|
$match: {
|
||||||
|
[matchCondition['contocom']]: contocom,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit appropriato
|
||||||
|
const limit = isEntrata ? numtransaz : numtransaz_uscita;
|
||||||
|
if (limit) {
|
||||||
|
pipeline.push({ $limit: limit });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiungi tutti i lookup rimanenti
|
||||||
|
pipeline.push(
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'users',
|
from: 'users',
|
||||||
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
let: { username: '$accfrom.username', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -834,15 +874,9 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
let: { groupname: '$accfrom.groupname', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -856,22 +890,15 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'circuits',
|
from: 'circuits',
|
||||||
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
let: { contocom: '$accfrom.contocom', idapp: '$accfrom.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -885,15 +912,6 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: 'accounts',
|
|
||||||
localField: 'accountToId',
|
|
||||||
foreignField: '_id',
|
|
||||||
as: 'accto',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ $unwind: '$accto' },
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: 'circuits',
|
from: 'circuits',
|
||||||
@@ -922,15 +940,9 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
let: { username: '$accto.username', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$username', '$username'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$username', '$username'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -950,15 +962,9 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
let: { groupname: '$accto.groupname', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$groupname', '$groupname'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$groupname', '$groupname'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -978,15 +984,9 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
let: { contocom: '$accto.contocom', idapp: '$accto.idapp' },
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{
|
{
|
||||||
$match:
|
$match: {
|
||||||
{
|
$expr: {
|
||||||
$expr:
|
$and: [{ $eq: ['$$contocom', '$path'] }, { $eq: ['$$idapp', '$idapp'] }],
|
||||||
{
|
|
||||||
$and:
|
|
||||||
[
|
|
||||||
{ $eq: ['$$contocom', '$path'] },
|
|
||||||
{ $eq: ['$$idapp', '$idapp'] },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1000,17 +1000,8 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
preserveNullAndEmptyArrays: true,
|
preserveNullAndEmptyArrays: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
|
||||||
if (querym2)
|
|
||||||
aggr1.push(querym2);
|
|
||||||
|
|
||||||
if (numtransaz)
|
|
||||||
aggr1.push({ $limit: numtransaz });
|
|
||||||
|
|
||||||
aggr1.push({
|
|
||||||
$project:
|
|
||||||
{
|
{
|
||||||
|
$project: {
|
||||||
transactionDate: 1,
|
transactionDate: 1,
|
||||||
amount: 1,
|
amount: 1,
|
||||||
causal: 1,
|
causal: 1,
|
||||||
@@ -1039,38 +1030,58 @@ MovementSchema.statics.getLastN_Transactions = async function (idapp, numtransaz
|
|||||||
'contocomto.path': 1,
|
'contocomto.path': 1,
|
||||||
'contocomto.name': 1,
|
'contocomto.name': 1,
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return pipeline;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Esegui entrambe le query in parallelo se necessario
|
||||||
|
let transazioniEntrata = [];
|
||||||
|
let transazioniUscita = [];
|
||||||
|
|
||||||
|
if (abilitaquerypersingolo) {
|
||||||
|
// Esegui le query separate per entrata e uscita
|
||||||
|
[transazioniEntrata, transazioniUscita] = await Promise.all([
|
||||||
|
numtransaz ? MyMovement.aggregate(buildPipeline(true)) : Promise.resolve([]),
|
||||||
|
numtransaz_uscita ? MyMovement.aggregate(buildPipeline(false)) : Promise.resolve([]),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Se non c'è filtro specifico, prendi solo le ultime N transazioni totali
|
||||||
|
const aggr1 = buildPipeline(false); // usa la pipeline base
|
||||||
|
if (numtransaz) {
|
||||||
|
// Rimuovi l'ultimo limit e aggiungine uno nuovo
|
||||||
|
aggr1.splice(
|
||||||
|
aggr1.findIndex((stage) => stage.$limit),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
aggr1.splice(3, 0, { $limit: numtransaz });
|
||||||
|
}
|
||||||
|
transazioniEntrata = await MyMovement.aggregate(aggr1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combina e ordina i risultati
|
||||||
|
const allTransactions = [...transazioniEntrata, ...transazioniUscita];
|
||||||
|
allTransactions.sort((a, b) => b.transactionDate - a.transactionDate);
|
||||||
|
|
||||||
|
// Processa i risultati
|
||||||
|
allTransactions.forEach(function (mov) {
|
||||||
|
let ris = tools.getStringaConto(mov);
|
||||||
|
mov.userfrom = ris.userfrom;
|
||||||
|
mov.userto = ris.userto;
|
||||||
|
mov.tipocontofrom = ris.tipocontofrom;
|
||||||
|
mov.tipocontoto = ris.tipocontoto;
|
||||||
});
|
});
|
||||||
|
|
||||||
const lastNtransac = await MyMovement.aggregate(aggr1);
|
return allTransactions;
|
||||||
|
|
||||||
/*
|
|
||||||
transacDate: Date
|
|
||||||
mitt_username: string
|
|
||||||
mitt_group: string
|
|
||||||
dest_username: string
|
|
||||||
dest_group: string
|
|
||||||
circuito: string
|
|
||||||
amount: number
|
|
||||||
causale: string
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
lastNtransac.forEach(function (mov) {
|
|
||||||
let ris = tools.getStringaConto(mov)
|
|
||||||
mov.userfrom = ris.userfrom
|
|
||||||
mov.userto = ris.userto
|
|
||||||
mov.tipocontofrom = ris.tipocontofrom
|
|
||||||
mov.tipocontoto = ris.tipocontoto
|
|
||||||
});
|
|
||||||
|
|
||||||
return lastNtransac;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Movement = mongoose.model('Movement', MovementSchema);
|
const Movement = mongoose.model('Movement', MovementSchema);
|
||||||
|
|
||||||
Movement.createIndexes()
|
Movement.createIndexes()
|
||||||
.then(() => { })
|
.then(() => {})
|
||||||
.catch((err) => { throw err; });
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = { Movement };
|
module.exports = { Movement };
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ const StatSchema = new Schema({
|
|||||||
|
|
||||||
StatSchema.statics.updateStats = async function (idapp, datastat) {
|
StatSchema.statics.updateStats = async function (idapp, datastat) {
|
||||||
|
|
||||||
datastat.last_transactions = await Movement.getLastN_Transactions(idapp, 5);
|
datastat.last_transactions = await Movement.getLastN_Transactions(idapp, 5, 5);
|
||||||
|
|
||||||
return datastat;
|
return datastat;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -427,13 +427,14 @@ router.patch('/:id', authenticate, (req, res) => {
|
|||||||
|
|
||||||
router.post('/lastmovs', authenticate, async (req, res) => {
|
router.post('/lastmovs', authenticate, async (req, res) => {
|
||||||
const nummov = req.body.nummov;
|
const nummov = req.body.nummov;
|
||||||
|
const nummov_uscita = req.body.nummov_uscita;
|
||||||
const idapp = req.body.idapp;
|
const idapp = req.body.idapp;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { Movement } = require('../models/movement');
|
const { Movement } = require('../models/movement');
|
||||||
|
|
||||||
if (nummov) {
|
if (nummov) {
|
||||||
last_transactions = await Movement.getLastN_Transactions(idapp, nummov);
|
last_transactions = await Movement.getLastN_Transactions(idapp, nummov, nummov_uscita);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send({ code: server_constants.RIS_CODE_OK, last_transactions });
|
res.send({ code: server_constants.RIS_CODE_OK, last_transactions });
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.2.76
|
1.2.77
|
||||||
Reference in New Issue
Block a user