ver "0.5.8"

Lista movimenti in formato Tabella
This commit is contained in:
Paolo Arena
2022-09-16 19:39:32 +02:00
parent 671a39e51c
commit 7b16362553
3 changed files with 172 additions and 30 deletions

View File

@@ -17,9 +17,9 @@ mongoose.plugin(schema => {
const MovementSchema = new Schema({
_id: {
type: String,
default: function () {
return new ObjectID().toString()
}
default: function() {
return new ObjectID().toString();
},
},
idapp: {
type: String,
@@ -74,7 +74,8 @@ MovementSchema.pre('save', async function(next) {
MovementSchema.statics.getFieldsForSearch = function() {
return [
{field: 'nome_conto', type: tools.FieldType.string},
{field: 'causal', type: tools.FieldType.string},
{field: 'amount', type: tools.FieldType.number},
];
};
@@ -176,26 +177,26 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
},
{$unwind: '$accto'},
{
"$lookup": {
"from": "circuits",
"localField": "accfrom.circuitId",
"foreignField": "_id",
"as": "circuitfrom"
}
'$lookup': {
'from': 'circuits',
'localField': 'accfrom.circuitId',
'foreignField': '_id',
'as': 'circuitfrom',
},
},
{
"$unwind": "$circuitfrom"
'$unwind': '$circuitfrom',
},
{
"$lookup": {
"from": "circuits",
"localField": "accto.circuitId",
"foreignField": "_id",
"as": "circuitto"
}
'$lookup': {
'from': 'circuits',
'localField': 'accto.circuitId',
'foreignField': '_id',
'as': 'circuitto',
},
},
{
"$unwind": "$circuitto"
'$unwind': '$circuitto',
},
{
$lookup: {
@@ -247,6 +248,151 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function(idapp, username,
return [];
};
MovementSchema.statics.getQueryAllUsersMovsByCircuitId = async function(idapp, circuitId) {
try {
if (!circuitId) {
return [];
}
let aggr1 = [
{
$match: {
idapp,
},
},
{
$lookup: {
from: 'accounts',
localField: 'accountFromId',
foreignField: '_id',
as: 'accfrom',
},
},
{$unwind: '$accfrom'},
{
$lookup: {
from: 'users',
let: {username: '$accfrom.username', idapp: '$accfrom.idapp'},
pipeline: [
{
$match:
{
$expr:
{
$and:
[
{$eq: ['$$username', '$username']},
{$eq: ['$$idapp', '$idapp']},
],
},
},
},
],
as: 'userfrom',
},
},
{
$unwind: {
path: '$userfrom',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'accounts',
localField: 'accountToId',
foreignField: '_id',
as: 'accto',
},
},
{
$unwind: {
path: '$accto',
preserveNullAndEmptyArrays: true,
},
},
{
'$lookup': {
'from': 'circuits',
'localField': 'accfrom.circuitId',
'foreignField': '_id',
'as': 'circuitfrom',
},
},
{
$unwind: {
path: '$circuitfrom',
preserveNullAndEmptyArrays: true,
},
},
{
'$lookup': {
'from': 'circuits',
'localField': 'accto.circuitId',
'foreignField': '_id',
'as': 'circuitto',
},
},
{
$unwind: {
path: '$circuitto',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'users',
let: {username: '$accto.username', idapp: '$accto.idapp'},
pipeline: [
{
$match:
{
$expr:
{
$and:
[
{$eq: ['$$username', '$username']},
{$eq: ['$$idapp', '$idapp']},
],
},
},
},
],
as: 'userto',
},
},
{
$unwind: {
path: '$userto',
preserveNullAndEmptyArrays: true,
},
},
{
$project:
{
transactionDate: 1,
amount: 1,
causal: 1,
'circuitfrom.symbol': 1,
'circuitto.symbol': 1,
'userfrom.username': 1,
'userfrom.profile.img': 1,
'userto.username': 1,
'userto.profile.img': 1,
},
},
];
return aggr1;
} catch (e) {
return [];
}
return [];
};
MovementSchema.statics.getMovsByCircuitId = async function(idapp, username, circuitId) {
const MyMovement = this;