File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 exportFrEsrPrizes ,
2424 exportFrEsrStructureIdentifiers ,
2525 exportFrEsrStructureWebsites ,
26+ exportFrEsrAnnelisPaysageMails ,
2627} from "./opendata" ;
2728import { sendMattermostNotification } from "./send-mattermost-notification" ;
2829import { monitorSiren , monitorSiret } from "./sirene" ;
@@ -113,6 +114,11 @@ agenda.define(
113114 { shouldSaveResult : true } ,
114115 exportFrEsrAnnelisPaysageEtablissements ,
115116) ;
117+ agenda . define (
118+ "export fr-esr-annelis-paysage-email-generiques" ,
119+ { shouldSaveResult : true } ,
120+ exportFrEsrAnnelisPaysageMails ,
121+ ) ;
116122agenda . define (
117123 "export fr-esr-paysage_structures_websites" ,
118124 { shouldSaveResult : true } ,
Original file line number Diff line number Diff line change 1+ import { client , db } from '../../services/mongo.service' ;
2+
3+ const dataset = 'fr-esr-annelis-paysage-email-generiques' ;
4+
5+ export default async function exportFrEsrAnnelisPaysageMails ( ) {
6+
7+ const emails = await db . collection ( 'emailtypes' ) . find ( { $and : [ { annelisId : { $ne : null } } , { annelisId : { $ne : "" } } ] } ) . toArray ( ) ;
8+ const emailMap = new Map ( emails . map ( email => [ email . id , email ] ) ) ;
9+
10+ const data = await db . collection ( 'emails' ) . aggregate ( [
11+ { $match : { emailTypeId : { $in : emails . map ( email => email . id ) } } } ,
12+ ] ) . toArray ( ) ;
13+
14+ const json = data . map ( ( elem ) => {
15+ const row = {
16+ dataset,
17+ eta_id_paysage : elem . resourceId ,
18+ annelis_email_type_id : emailMap . get ( elem . emailTypeId ) ?. annelisId || '' ,
19+ annelis_email_type : emailMap . get ( elem . emailTypeId ) ?. usualName || '' ,
20+ annelis_email : elem . email
21+ } ;
22+ return row ;
23+ } ) ;
24+ const session = client . startSession ( ) ;
25+ await session . withTransaction ( async ( ) => {
26+ await db . collection ( 'opendata' ) . deleteMany ( { dataset } ) ;
27+ await db . collection ( 'opendata' ) . insertMany ( json ) ;
28+ await session . endSession ( ) ;
29+ } ) ;
30+
31+ return { status : 'success' , location : `/opendata/${ dataset } ` } ;
32+ }
Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ export { default as exportFrEsrPersonIdentifiers } from './fr-esr-paysage_person
55export { default as exportFrEsrStructureWebsites } from './fr-esr-paysage_structures_websites' ;
66export { default as exportFrEsrPrizes } from './fr-esr-paysage_prix' ;
77export { default as exportFrEsrPaysageLaureatAll } from './fr_esr_paysage_laureats_all' ;
8+ export { default as exportFrEsrAnnelisPaysageMails } from './fr-esr-annelis-paysage-email-generiques' ;
You can’t perform that action at this time.
0 commit comments