Skip to content

Commit

Permalink
feat(jobs): add prizes jobs to creat dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Feb 1, 2024
1 parent 8cc7920 commit dd735e5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api/opendata/opendata.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const FILTERS = {
'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' },
'fr-esr-paysage_prix': { dataset: 'fr-esr-paysage_prix' },

};

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 @@ -18,6 +18,7 @@ import {
exportFrEsrStructureIdentifiers,
exportFrEsrPersonIdentifiers,
exportFrEsrStructureWebsites,
exportFrEsrPrizes,
} from './opendata';
import synchronizeAnnuaireCollection from './synchronize/annuaire-collection';
import synchronizeCuriexploreActors from './synchronize/curiexplore-actors';
Expand All @@ -38,6 +39,7 @@ agenda.define('send recovery email', { shouldSaveResult: true }, sendPasswordRec
agenda.define('send contact email', { shouldSaveResult: true }, sendContactEmail);
agenda.define('update key numbers', { shouldSaveResult: true }, updateKeyNumbers);
agenda.define('reindex', { shouldSaveResult: true }, reindex);
agenda.define('export fr-esr-paysage_prix', { shouldSaveResult: true }, exportFrEsrPrizes);
agenda.define('export fr-esr-paysage_structures_identifiants', { shouldSaveResult: true }, exportFrEsrStructureIdentifiers);
agenda.define('export fr-esr-paysage_personnes_identifiants', { shouldSaveResult: true }, exportFrEsrPersonIdentifiers);
agenda.define('export fr-esr-paysage-fonctions-gourvernance', { shouldSaveResult: true }, exportFrEsrPaysageFonctionsGourvernance);
Expand Down
54 changes: 54 additions & 0 deletions src/jobs/opendata/fr-esr-paysage_prix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { client, db } from '../../services/mongo.service';

const dataset = 'fr-esr-paysage_prix';

export default async function exportFrEsrPrizes() {
const json = await db.collection('prizes').aggregate([
{
$lookup: {
from: 'relationships',
let: { prizeId: '$id' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$resourceId', '$$prizeId'] },
{ $eq: ['$relationTag', 'prix-porteur'] },
],
},
},
},
],
as: 'relationshipData',
},
},
{
$project: {
dataset,
id_paysage: '$id',
nameFr: '$nameFr',
nameEn: '$nameEn',
descriptionFr: '$descriptionFr',
descriptionEn: '$descriptionEn',
relatedObjectId: {
$ifNull: [{ $arrayElemAt: ['$relationshipData.relatedObjectId', 0] }, null],
},
},
},
{
$match: {
id_paysage: { $exists: true },
},
},
]).toArray();

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 @@ -3,3 +3,4 @@ export { default as exportFrEsrAnnelisPaysageEtablissements } from './fr-esr-ann
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';
export { default as exportFrEsrPrizes } from './fr-esr-paysage_prix';

0 comments on commit dd735e5

Please sign in to comment.