Improve loading for manage games page
parent
05473e07ad
commit
55a6fc7d7b
|
@ -209,7 +209,7 @@ CATEGORIES.push(new Category(
|
||||||
CATEGORIES.push(new Category(
|
CATEGORIES.push(new Category(
|
||||||
"games",
|
"games",
|
||||||
async function getGames() {
|
async function getGames() {
|
||||||
return await Data.getGames();
|
return await (await fetch('/fetch/manage/games')).json();
|
||||||
},
|
},
|
||||||
async function listGameHeaders() {
|
async function listGameHeaders() {
|
||||||
const headerRow = document.createElement('tr');
|
const headerRow = document.createElement('tr');
|
||||||
|
@ -242,12 +242,12 @@ CATEGORIES.push(new Category(
|
||||||
function listGame(game, row) {
|
function listGame(game, row) {
|
||||||
const teamsCell = document.createElement('td');
|
const teamsCell = document.createElement('td');
|
||||||
const team1NameSpan = document.createElement('span');
|
const team1NameSpan = document.createElement('span');
|
||||||
Data.getTeam(game.team1ID)
|
let team1Name = game.team1.name;
|
||||||
.then(data => team1NameSpan.textContent = data.name);
|
team1NameSpan.textContent = team1Name;
|
||||||
teamsCell.appendChild(team1NameSpan);
|
teamsCell.appendChild(team1NameSpan);
|
||||||
const team2NameSpan = document.createElement('span');
|
const team2NameSpan = document.createElement('span');
|
||||||
Data.getTeam(game.team2ID)
|
let team2Name = game.team2.name;
|
||||||
.then(data => team2NameSpan.textContent = data.name);
|
team2NameSpan.textContent = team2Name;
|
||||||
teamsCell.appendChild(team2NameSpan);
|
teamsCell.appendChild(team2NameSpan);
|
||||||
row.appendChild(teamsCell);
|
row.appendChild(teamsCell);
|
||||||
|
|
||||||
|
@ -271,13 +271,11 @@ CATEGORIES.push(new Category(
|
||||||
const divisionGenderSpan = document.createElement('span');
|
const divisionGenderSpan = document.createElement('span');
|
||||||
divisionSpan.appendChild(divisionNameSpan);
|
divisionSpan.appendChild(divisionNameSpan);
|
||||||
divisionSpan.appendChild(divisionGenderSpan);
|
divisionSpan.appendChild(divisionGenderSpan);
|
||||||
Data.getDivision(game.divisionID)
|
let divisionName = game.division.name;
|
||||||
.then(data => {
|
let sportName = game.sport.name;
|
||||||
Data.getSportName(data.sportID)
|
divisionNameSpan.textContent = divisionName;
|
||||||
.then(data => sportSpan.textContent = data);
|
sportSpan.textContent = sportName;
|
||||||
divisionNameSpan.textContent = data.name;
|
divisionGenderSpan.textContent = getGenderLetter(game.division.gender.name);
|
||||||
divisionGenderSpan.textContent = getGenderLetter(data.gender.name);
|
|
||||||
});
|
|
||||||
sportCell.appendChild(sportSpan);
|
sportCell.appendChild(sportSpan);
|
||||||
sportCell.appendChild(divisionSpan);
|
sportCell.appendChild(divisionSpan);
|
||||||
row.appendChild(sportCell);
|
row.appendChild(sportCell);
|
||||||
|
@ -293,11 +291,10 @@ CATEGORIES.push(new Category(
|
||||||
|
|
||||||
const submitterCell = document.createElement('td');
|
const submitterCell = document.createElement('td');
|
||||||
if(game.submitterID) {
|
if(game.submitterID) {
|
||||||
Data.getAccount(game.submitterID)
|
let submitterName = game.submitter.name;
|
||||||
.then(data => submitterCell.textContent = data.name);
|
submitterCell.textContent = submitterName;
|
||||||
} else {
|
} else {
|
||||||
submitterCell.textContent = game.submitterName;
|
submitterCell.textContent = game.submitterName;
|
||||||
console.log(game.submitterName);
|
|
||||||
}
|
}
|
||||||
row.appendChild(submitterCell);
|
row.appendChild(submitterCell);
|
||||||
},
|
},
|
||||||
|
|
|
@ -146,4 +146,31 @@ router.get('/manage/teams', async function (req, res, next) {
|
||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) {
|
||||||
|
try{
|
||||||
|
const userIsAdmin = req.user[2];
|
||||||
|
const loggedInAccountID = req.user[0];
|
||||||
|
|
||||||
|
if(!userIsAdmin) {
|
||||||
|
res.status(403).send("ACCESS DENIED");
|
||||||
|
} else {
|
||||||
|
const data = await games.retrieve();
|
||||||
|
|
||||||
|
for(const game of data) {
|
||||||
|
game.team1 = await teams.getFromID(game.team1ID);
|
||||||
|
game.team2 = await teams.getFromID(game.team2ID);
|
||||||
|
game.division = await divisions.getFromID(game.divisionID);
|
||||||
|
game.sport = await sports.getFromID(game.division.sportID);
|
||||||
|
game.submitter = game.submitterName || (await accounts.getFromID(game.submitterID));
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(data);
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
res.status(500).send("An error has occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
Reference in New Issue