@@ -2,6 +2,22 @@ import currentLegalCategoryQuery from './current-legal-category.query';
22import currentLocalisationQuery from './current-localisation.query' ;
33import currentNameQuery from './current-name.query' ;
44
5+ const currentLegalRelationshipIdQuery = [
6+ {
7+ $lookup : {
8+ from : 'relationships' ,
9+ let : { item : '$id' } ,
10+ pipeline : [
11+ { $match : { $expr : { $and : [ { $eq : [ '$resourceId' , '$$item' ] } , { $eq : [ '$relationTag' , 'structure-categorie-juridique' ] } ] } } } ,
12+ { $sort : { startDate : 1 } } ,
13+ ] ,
14+ as : 'legalcategoryRelationshipId' ,
15+ } ,
16+ } ,
17+ { $set : { legalcategoryRelationshipId : '$legalcategoryRelationshipId.id' } } ,
18+ { $set : { legalcategoryRelationshipId : { $arrayElemAt : [ '$legalcategoryRelationshipId' , 0 ] } } } ,
19+ ] ;
20+
521const currentSiretQuery = [
622 {
723 $lookup : {
@@ -33,6 +49,7 @@ const structQuery = [
3349 ...currentLocalisationQuery ,
3450 ...currentNameQuery ,
3551 ...currentSiretQuery ,
52+ ...currentLegalRelationshipIdQuery ,
3653 {
3754 $project : {
3855 _id : 0 ,
@@ -47,6 +64,7 @@ const structQuery = [
4764 href : { $concat : [ '/structures/' , '$id' ] } ,
4865 legalcategory : { $ifNull : [ '$legalcategory' , { } ] } ,
4966 structureStatus : { $ifNull : [ '$structureStatus' , 'active' ] } ,
67+ legalcategoryRelationshipId : 1 ,
5068 } ,
5169 } ,
5270] ;
0 commit comments