Move SinusBotService to backend

This commit is contained in:
2020-05-30 19:32:12 +02:00
parent 32ce290a13
commit 5925872ac8
8 changed files with 129 additions and 59 deletions

View File

@@ -16,23 +16,7 @@ export default class App extends React.Component {
}
componentDidMount() {
fetch('https://sinusbot.humenius.me/api/v1/bot/i/51314e26-13a1-4779-b2ac-e36d493687d4/event/tunakill_rank_all_user')
.then(res => res.json())
.then((data) => SinusBotService.consumeTunakillResponse(data))
.then(
(result) => {
this.setState({
isLoaded: true,
users: result
});
},
(error) => {
this.setState({
isLoaded: true,
error: error
});
}
);
}
render() {

View File

@@ -1,40 +0,0 @@
import TableEntry from "../models/TableEntry";
import TunaKillUser from "../models/TunaKillUser";
class SinusBotService {
public static consumeTunakillResponse(data: any): TableEntry[] | undefined {
if (!(data !== null || data[0] !== null || data[0].data !== null)) {
return undefined;
}
const response = data[0].data;
if (!(response.length > 0)) {
return undefined;
}
return response
.map((user: TunaKillUser) => {
if (user.name === "Server Query Admin") { return null; }
return {
name: user.name,
rawTime: user.time,
onlineTime: new Date(user.time * 1000)
.toISOString()
.substr(11, 8)
};
})
.sort((a: any, b: any) => {
if (a.rawTime < b.rawTime) {
return -1;
}
if (a.rawTime > b.rawTime) {
return 1;
}
return 0;
});
}
}
export default SinusBotService;