diff --git a/public/scripts/manage/team.js b/public/scripts/manage/team.js index cd5ac95..a7eadce 100644 --- a/public/scripts/manage/team.js +++ b/public/scripts/manage/team.js @@ -14,14 +14,18 @@ async function initializeForm() { let params = new URLSearchParams(location.search); let teamID = params.get('team'); if(teamID) { - const team = await Data.getTeam(teamID); + const team = await (await fetch(`/fetch/manage/team?team=${teamID}`)).json(); nameTextbox.value = team.name; deleteButton.style.visibility = "visible"; deleteButton.disabled = false; - Form.populateSports(sportDropdown, team.sportID); + let data = {}; + data.sports = [team.sport]; + data.latestGame = {sportID : team.sportID }; + + Form.populateSports(sportDropdown, null, data); Form.addHiddenValue('team', teamID, submissionForm); } diff --git a/routes/data.js b/routes/data.js index b6769d5..55c1970 100644 --- a/routes/data.js +++ b/routes/data.js @@ -98,7 +98,7 @@ router.get('/team', async function(req, res, next) { console.error("ERROR: " + err.message); res.status(500).send("An error has occurred"); } -}) +}); router.get('/games', async function(req, res, next) { try { diff --git a/routes/fetch.js b/routes/fetch.js index f807190..4958fd3 100644 --- a/routes/fetch.js +++ b/routes/fetch.js @@ -158,6 +158,18 @@ router.get('/manage/teams', async function (req, res, next) { res.json(data); }); +router.get('/manage/team', async function (req, res, next) { + try { + const teamID = req.query.team; + const data = await teams.getFromID(teamID); + data.sport = await sports.getFromID(data.sportID); + res.json(data); + } catch(err) { + console.error("ERROR: " + err.message); + res.status(500).send("An error has occurred"); + } +}); + router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) { try{ const userIsAdmin = req.user[2];