Skip to content

Commit 6d0eb70

Browse files
committed
Merge branch 'staging'
2 parents 7472290 + 25def82 commit 6d0eb70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/api/commons/queries/sirene-updates.query.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ import currentLegalCategoryQuery from './current-legal-category.query';
22
import currentLocalisationQuery from './current-localisation.query';
33
import 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+
521
const 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

Comments
 (0)