diff options
author | mat <github@matdoes.dev> | 2022-02-12 22:34:17 -0600 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-02-12 22:34:17 -0600 |
commit | aa4d561f1663c85e9dec8e3d2e76c14cbea997bb (patch) | |
tree | c8d887e37f952f068a2297769a9ae3d60ea99412 /src/cleaners | |
parent | e10181e7763ebb3ec7b16e0612875727665df552 (diff) | |
download | skyblock-api-aa4d561f1663c85e9dec8e3d2e76c14cbea997bb.tar.gz skyblock-api-aa4d561f1663c85e9dec8e3d2e76c14cbea997bb.tar.bz2 skyblock-api-aa4d561f1663c85e9dec8e3d2e76c14cbea997bb.zip |
Election API
Diffstat (limited to 'src/cleaners')
-rw-r--r-- | src/cleaners/skyblock/election.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/election.ts b/src/cleaners/skyblock/election.ts new file mode 100644 index 0000000..78937ec --- /dev/null +++ b/src/cleaners/skyblock/election.ts @@ -0,0 +1,64 @@ + +const candidateColors = { + barry: 'e', + paul: '4', + aatrox: 'a', + foxy: '3', + cole: 'e', + marina: '5', + diaz: '5', + diana: '3', +} + +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): Candidate { + return { + name: data.name, + perks: data.perks, + votes: data.votes, + color: candidateColors[data.name.toLowerCase()], + } +} + +export function cleanElectionResponse(data: any): ElectionData { + return { + last_updated: data.lastUpdated / 1000, + previous: { + year: data.mayor.election.year, + winner: cleanCandidate({ + name: data.mayor.name, + perks: data.mayor.perks, + votes: data.mayor.election.candidates.find(c => c.key === data.mayor.key).votes, + }), + candidates: data.mayor.election.candidates.map(cleanCandidate) + }, + current: data.current ? { + year: data.current.year, + candidates: data.current.candidates.map(cleanCandidate) + } : null + } +}
\ No newline at end of file |