From 980d2eac3de373978c8b0af54d05c8060d8f44cb Mon Sep 17 00:00:00 2001 From: JP1998 Date: Thu, 11 Apr 2019 16:19:17 +0200 Subject: [PATCH] Fix a bug, which causes the tournament site to crash Whenever a match in the play off stage of a tournament has not had a team determined yet the tournament site would crash on it since it expected two team objects attached. --- pages/tournament.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/pages/tournament.js b/pages/tournament.js index 547fcf8..1f8797e 100644 --- a/pages/tournament.js +++ b/pages/tournament.js @@ -361,14 +361,29 @@ function convertGroup(apiGroup) { } function convertMatch(apiMatch) { - return { + var result = { id: apiMatch.id, - state: apiMatch.state, - team1: apiMatch.match_scores[0].team.name, - team2: apiMatch.match_scores[1].team.name, - scoreTeam1: apiMatch.match_scores[0].points, - scoreTeam2: apiMatch.match_scores[1].points + state: apiMatch.state }; + + if(apiMatch.match_scores.length == 2) { + result.team1 = apiMatch.match_scores[0].team.name; + result.scoreTeam1 = apiMatch.match_scores[0].points; + result.team2 = apiMatch.match_scores[1].team.name; + result.scoreTeam2 = apiMatch.match_scores[1].points; + } else if(apiMatch.match_scores.length == 1) { + result.team1 = apiMatch.match_scores[0].team.name; + result.scoreTeam1 = apiMatch.match_scores[0].points; + result.team2 = 'TBD'; + result.scoreTeam2 = 0; + } else { + result.team1 = 'TBD'; + result.scoreTeam1 = 0; + result.team2 = 'TBD'; + result.scoreTeam2 = 0; + } + + return result; } class Main extends React.Component {