♻️ Refactor backend and add comments

This commit is contained in:
2022-05-19 00:22:55 +02:00
parent 73dc67e6b4
commit 9fad079102
5 changed files with 86 additions and 25 deletions

View File

@ -1,9 +1,9 @@
import axios from "axios";
const baseurl = "https://mobileapi.dsbcontrol.de";
const baseUrl = "https://mobileapi.dsbcontrol.de";
export async function getAuthtoken(username, password) {
const response = await axios.get(
`${baseurl}/authid?user=${username}&password=${password}&bundleid&appversion&osversion&pushid`
`${baseUrl}/authid?user=${username}&password=${password}&bundleid&appversion&osversion&pushid`
);
if (response.data == "") throw "Wrong username or password";
return response.data;
@ -11,13 +11,15 @@ export async function getAuthtoken(username, password) {
export async function getTimetables(authtoken) {
const response = await axios.get(
`${baseurl}/dsbtimetables?authid=${authtoken}`
`${baseUrl}/dsbtimetables?authid=${authtoken}`
);
const timetables = response.data;
const urls = [];
timetables.forEach((timetable) => {
const rawTimestamp = timetable.Date;
// Convert the timestamp to the correct
// format so new Date() accepts it
const date = rawTimestamp.split(" ")[0].split(".").reverse().join("-");
const time = rawTimestamp.split(" ")[1];
const timestamp = date + " " + time;