Skip to content

Commit

Permalink
fix(weblinks): add new task for weblinks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jan 26, 2024
1 parent 01d5a9e commit 8cc7920
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/opendata/opendata.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const FILTERS = {
'fr-esr-annelis-paysage-etablissements': { dataset: 'fr-esr-annelis-paysage-etablissements' },
'fr-esr-paysage_structures_identifiants': { dataset: 'fr-esr-paysage_structures_identifiants' },
'fr-esr-paysage_personnes_identifiants': { dataset: 'fr-esr-paysage_personnes_identifiants' },
'fr-esr-paysage_structures_websites': { dataset: 'fr-esr-paysage_structures_websites' },
};

router.route('/opendata/:datasetId')
Expand Down
2 changes: 2 additions & 0 deletions src/jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
exportFrEsrAnnelisPaysageEtablissements,
exportFrEsrStructureIdentifiers,
exportFrEsrPersonIdentifiers,
exportFrEsrStructureWebsites,
} from './opendata';
import synchronizeAnnuaireCollection from './synchronize/annuaire-collection';
import synchronizeCuriexploreActors from './synchronize/curiexplore-actors';
Expand All @@ -41,6 +42,7 @@ agenda.define('export fr-esr-paysage_structures_identifiants', { shouldSaveResul
agenda.define('export fr-esr-paysage_personnes_identifiants', { shouldSaveResult: true }, exportFrEsrPersonIdentifiers);
agenda.define('export fr-esr-paysage-fonctions-gourvernance', { shouldSaveResult: true }, exportFrEsrPaysageFonctionsGourvernance);
agenda.define('export fr-esr-annelis-paysage-etablissements', { shouldSaveResult: true }, exportFrEsrAnnelisPaysageEtablissements);
agenda.define('export fr-esr-paysage_structures_websites', { shouldSaveResult: true }, exportFrEsrStructureWebsites);
agenda.define('synchronize fr-esr-referentiel-geographique', { shouldSaveResult: true }, synchronizeFrEsrReferentielGeographique);
agenda.define('synchronize curiexplore actors', { shouldSaveResult: true }, synchronizeCuriexploreActors);
agenda.define('ask for email revalidation with otp', { shouldSaveResult: true }, askForEmailRevalidation);
Expand Down
42 changes: 42 additions & 0 deletions src/jobs/opendata/fr-esr-paysage_structures_websites.js
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}` };
}
1 change: 1 addition & 0 deletions src/jobs/opendata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as exportFrEsrPaysageFonctionsGourvernance } from './fr-esr-pay
export { default as exportFrEsrAnnelisPaysageEtablissements } from './fr-esr-annelis-paysage-etablissements';
export { default as exportFrEsrStructureIdentifiers } from './fr-esr-paysage_structures_identifiants';
export { default as exportFrEsrPersonIdentifiers } from './fr-esr-paysage_personnes_identifiants';
export { default as exportFrEsrStructureWebsites } from './fr-esr-paysage_structures_websites';

0 comments on commit 8cc7920

Please sign in to comment.