Circuit table...

This commit is contained in:
paoloar77
2022-08-26 03:33:13 +02:00
parent 5dfcd4f7fa
commit a2019c6ac9
5 changed files with 234 additions and 10 deletions

View File

@@ -242,6 +242,7 @@ MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
createdBy: 1,
date_created: 1,
date_updated: 1,
circuits_list: 1,
};
};
@@ -258,6 +259,7 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
note: 1,
date_created: 1,
date_updated: 1,
circuits_list: 1,
};
};
@@ -286,10 +288,49 @@ MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname)
const whatToShow = this.getWhatToShow(idapp, groupname);
const rec = await MyGroup.findOne({
const myfind = {
idapp,
groupname,
}, whatToShow).lean();
};
const query = [
{$match: myfind},
{ $unwind: '$circuits_list' },
{
$lookup: {
from: 'circuits',
localField: 'circuits_list.Num',
foreignField: 'Num',
as: 'mycircuits',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$mycircuits',
0,
],
},
'$$ROOT',
],
},
},
},
{$project: whatToShow},
];
try {
const ris = await MyGroup.aggregate(query);
if (ris && ris.length > 0)
return ris[0];
} catch (e) {
return null;
}
return rec;