Circuit table...
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user