-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(weblinks): add new task for weblinks
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import structuresLightQuery from '../../api/commons/queries/structures.light.query'; | ||
import { client, db } from '../../services/mongo.service'; | ||
|
||
const dataset = 'fr-esr-paysage_structures_websites'; | ||
|
||
export default async function exportFrEsrStructureWebsites() { | ||
const data = await db.collection('weblinks').aggregate([ | ||
{ | ||
$lookup: { | ||
from: 'structures', | ||
localField: 'resourceId', | ||
foreignField: 'id', | ||
pipeline: structuresLightQuery, | ||
as: 'structure', | ||
}, | ||
}, | ||
{ $set: { structure: { $arrayElemAt: ['$structure', 0] } } }, | ||
]).toArray(); | ||
const json = data.map(({ structure, ...websites }) => { | ||
if (!structure || !structure.id || !websites || !websites.id) { | ||
return null; | ||
} | ||
const row = { | ||
dataset, | ||
url: websites.url, | ||
internal_id: websites.id, | ||
id_structure_paysage: structure.id, | ||
type: websites.type, | ||
language: websites.language, | ||
}; | ||
return row; | ||
}).filter((row) => row !== null); | ||
|
||
const session = client.startSession(); | ||
await session.withTransaction(async () => { | ||
await db.collection('opendata').deleteMany({ dataset }); | ||
await db.collection('opendata').insertMany(json); | ||
await session.endSession(); | ||
}); | ||
|
||
return { status: 'success', location: `/opendata/${dataset}` }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters