diff --git a/database/scores/games.js b/database/scores/games.js index 9f27bab..4055523 100644 --- a/database/scores/games.js +++ b/database/scores/games.js @@ -58,12 +58,17 @@ async function retrieve(teamID, divisionID, seasonID) { const gamesList = []; table.forEach((row) => { - opponentIsTeam2 = teamID != row[5]; - opponentID = opponentIsTeam2 ? row[5] : row[4]; - teamScore = opponentIsTeam2 ? row[6] : row[7]; - opponentScore = opponentIsTeam2 ? row[7] : row[6]; - - gamesList.push(new Game(row[0], row[3].toISOString().slice(0,10), teamID, opponentID, teamScore, opponentScore, row[1], row[2])); + if(teamID) { + const opponentIsTeam2 = teamID != row[5]; + const opponentID = opponentIsTeam2 ? row[5] : row[4]; + const teamScore = opponentIsTeam2 ? row[6] : row[7]; + const opponentScore = opponentIsTeam2 ? row[7] : row[6]; + + gamesList.push(new Game(row[0], row[3].toISOString().slice(0,10), teamID, opponentID, teamScore, opponentScore, row[1], row[2])); + } + else { + gamesList.push(new Game(row[0], row[3].toISOString().slice(0,10), row[4], row[5], row[6], row[7], row[1], row[2])); + } }); return gamesList; }