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
53
54
55
56
|
const candidateColors = [
'4', 'a', '3', 'e', '5',
]
export interface MayorPerk {
name: string
description: string
}
export interface Candidate {
name: string
perks: MayorPerk[]
votes: number
color: string | null
}
export interface ElectionData {
last_updated: number
previous: {
year: number
winner: Candidate
candidates: Candidate[]
}
current: {
year: number
candidates: Candidate[]
} | null
}
function cleanCandidate(data: any, index: number): Candidate {
return {
name: data.name,
perks: data.perks.map(perk => ({
name: perk.name,
description: '§7' + perk.description,
})),
votes: data.votes,
color: candidateColors[index],
}
}
export function cleanElectionResponse(data: any): ElectionData {
const previousCandidates = data.mayor.election.candidates.map(cleanCandidate)
return {
last_updated: data.lastUpdated / 1000,
previous: {
year: data.mayor.election.year,
winner: data.mayor.name,
candidates: previousCandidates
},
current: data.current ? {
year: data.current.year,
candidates: data.current.candidates.map(cleanCandidate)
} : null
}
}
|