This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues or pull requests.
score-tracker/public/scripts/data.js
2021-11-22 14:58:43 -07:00

45 lines
No EOL
1.4 KiB
JavaScript

export async function getSports() {
const response = await fetch('/data/sports');
const sportsList = await response.json();
return sportsList;
}
export async function getSeasons() {
const response = await fetch('/data/seasons');
const seasonsList = await response.json();
return seasonsList;
}
export async function getGenders(sportID) {
const response = await fetch(`/data/genders?sport=${+sportID}`);
const gendersList = await response.json();
return gendersList;
}
export async function getDivisions(sportID = undefined, gender = undefined) {
let URL = '/data/divisions?';
if(sportID) URL += `sport=${+sportID}&`;
if(gender) URL += `gender=${gender}&`;
const response = await fetch(URL);
const divisionsList = await response.json();
return divisionsList;
}
export async function getTeams(sportID) {
const response = await fetch(`/data/teams?sport=${+sportID}`);
const teamsList = await response.json();
return teamsList;
}
export async function getTeamName(teamID) {
const response = await fetch(`/data/team?team=${+teamID}`);
const team = await response.json();
return team.name;
}
export async function getGames(teamID, divisionID, seasonID) {
const response = await fetch(`/data/games?team=${+teamID}&division=${+divisionID}&season=${+seasonID}`);
const gamesList = await response.json();
return gamesList;
}