From 05473e07ad4949504a1abbfe116cd75e228dee07 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Wed, 9 Mar 2022 10:32:47 -0700 Subject: [PATCH] Speed up loading teams --- public/scripts/manage.js | 6 +++--- routes/fetch.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/scripts/manage.js b/public/scripts/manage.js index a96bac9..6fc6b07 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -166,7 +166,7 @@ CATEGORIES.push(new Category( CATEGORIES.push(new Category( "teams", async function getTeams() { - return await Data.getTeams(); + return await (await fetch('/fetch/manage/teams')).json(); }, async function listTeamHeaders() { const headerRow = document.createElement('tr'); @@ -194,8 +194,8 @@ CATEGORIES.push(new Category( row.appendChild(spacerCell); const sportCell = document.createElement('td'); - Data.getSportName(team.sportID) - .then(data => sportCell.textContent = data); + let sportName = team.sport.name; + sportCell.textContent = sportName; row.appendChild(sportCell); }, async function addTeam() { diff --git a/routes/fetch.js b/routes/fetch.js index 28a98ea..c140ead 100644 --- a/routes/fetch.js +++ b/routes/fetch.js @@ -136,4 +136,14 @@ router.get('/manage/divisions', async function (req, res, next) { res.json(data); }); +router.get('/manage/teams', async function (req, res, next) { + const data = await teams.retrieve(); + + for(const team of data) { + team.sport = await sports.getFromID(team.sportID); + } + + res.json(data); +}); + module.exports = router; \ No newline at end of file