-
Notifications
You must be signed in to change notification settings - Fork 6
/
GroupCSVReport.js
33 lines (27 loc) · 1.03 KB
/
GroupCSVReport.js
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
// See README.md for a description of this script.
const xm = require('xmtoolbox');
const fs = require('fs').promises;
const { np } = require('./config');
const env = np;
const path = `./data/${env.subdomain}-groups.csv`;
(async () => {
//get all groups with their supervisors
const groups = await xm.groups.getMany(env, { embed: 'supervisors' });
//flatten group data and only extract the group name and the supervisors name and id
const data = groups.map(({ targetName, supervisors }) => {
const Supervisors = supervisors.data.map(
({ targetName, firstName, lastName }) => `${firstName} ${lastName}(${targetName})`
);
return { Group: targetName, Supervisors };
});
//convert json array to csv with xmtoolbox utilities
const csv = xm.util.JsonToCsv(data);
//write the report to a file
fs.writeFile(path, csv); //Note: multiple supervisors are delimited by a comma.
/*
Example Output:
Group,Supervisors
Web Team,"Brannon Vann(bvann),John Smith(jsmith)"
Database Operations,Brannon Vann(bvann)
*/
})();