-
Notifications
You must be signed in to change notification settings - Fork 0
/
bso-local-variation-validation.mjs
52 lines (48 loc) · 1.62 KB
/
bso-local-variation-validation.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// node bso-local-variation-validation.mjs anne.lhote@gmail.com,anne.lhote@recherche.gouv.fr 130015506
import Axios from 'axios';
import https from 'node:https';
import locals from './src/config/locals.json' assert { type: "json" };
const sendEmail = (emails, structureId, structureName) => {
const to = emails.split(',').map((email) => ({ email, name: email }))
const options = {
method: 'POST',
url: 'https://barometredelascienceouverte.esr.gouv.fr/mailer/',
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
headers: { 'Content-Type': 'application/json' },
data: {
to: [
{
email: 'bso@recherche.gouv.fr',
// Encode UTF8
name: JSON.parse(JSON.stringify('Baromètre français de la Science Ouverte')),
},
...to,
],
templateId: 234,
params:{
"structureName": structureName,
"structureId": structureId,
},
},
};
Axios.request(options)
.then(() => {
console.log('Email sent');
})
.catch((e) => {
console.error('!!! ERROR !!!');
console.error(e);
});
};
if (process.argv.length === 4) {
const emails = process.argv[2];
const structureId = process.argv[3];
const structureName = locals?.[structureId.toUpperCase()]?.commentsName;
if (structureName) {
sendEmail(emails, structureId.toLowerCase(), structureName);
} else {
console.error(`This structureId "${structureId.toUpperCase()}" does not exists in locals config file (src/config/locals.json).`);
}
} else {
console.error('Misuse, this command line require 2 arguments : email address and structure id');
}