-
Notifications
You must be signed in to change notification settings - Fork 5
/
winners.js
47 lines (44 loc) · 1.05 KB
/
winners.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fetch = require('node-fetch');
const stringify = require('csv-stringify/lib/sync');
const fs = require('fs');
const query = `
query {
showcase {
projects(where: { awarded: true, eventGroup: "${process.argv[2]}" }) {
name
awards {
type
}
members {
account {
name
discordId
}
}
}
}
}
`;
(async () => {
const response = await fetch('http://graph.codeday.org', {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify({ query, variables: {}, }),
});
const result = await response.json();
const table = result?.data?.showcase.projects
.map((p) => ({
project: p.name,
award: p.awards[0]?.type,
members: p.members,
}))
.map(({ members, ...rest }) => members.map((m) => ({
...rest,
name: m.account?.name,
discord: m.account?.discordId,
})))
.reduce((accum, e) => [...accum, ...e], []);
console.log(stringify(table, { header: true }));
})();