From 37166665cd7e00997c017d0a446b8b2caa8a8a66 Mon Sep 17 00:00:00 2001 From: Piotr Witold Rynio <41823689+PiotrWR@users.noreply.github.com> Date: Thu, 15 Apr 2021 00:14:34 +0200 Subject: [PATCH] Frontend | Adjust matches list for backend endpoints --- .../organisms/MatchesList/MatchesList.tsx | 29 +++++++++++++++---- .../restapi/match-details/MatchDetailsDto.tsx | 4 +-- .../match-details/MatchDetailsRestAPI.ts | 4 +-- .../TournamentDetailsRestApi.ts | 4 +-- .../TournamentMatchesListRestAPI.ts | 2 +- .../TournamentTeamsListRestApi.ts | 2 +- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/organisms/MatchesList/MatchesList.tsx b/frontend/src/components/organisms/MatchesList/MatchesList.tsx index 2ed50ccc..df907347 100644 --- a/frontend/src/components/organisms/MatchesList/MatchesList.tsx +++ b/frontend/src/components/organisms/MatchesList/MatchesList.tsx @@ -30,6 +30,16 @@ export const MatchesList = ({tournamentId}: MatchesListProps) => { const [playersProfilesListDto, setPlayersProfilesListDto] = React.useState(undefined); const [matchesList, setMatchesList] = React.useState(); + + console.log("tuuuu"); + console.log(expanded); + console.log(tournamentMatchesListDto); + console.log(matchesDetailsListDto); + console.log(tournamentTeamsListDto); + console.log(playersProfilesListDto); + console.log(matchesList); + + useEffect(() => { reloadAllList() }, [tournamentId]); @@ -38,7 +48,7 @@ export const MatchesList = ({tournamentId}: MatchesListProps) => { if (!tournamentMatchesListDto) return; Promise.all(tournamentMatchesListDto.queue - .map((tournamentMatchesItem) => getMatchDetailsDto(`${tournamentId}_${tournamentMatchesItem.matchNumber}`))) + .map((tournamentMatchesItem) => getMatchDetailsDto(`${tournamentId}_${tournamentMatchesItem.matchNumber}`, tournamentMatchesItem.team1Id, tournamentMatchesItem.team2Id))) .then(matchesDetailsDto => setMatchesDetailsListDto(matchesDetailsDto)) getTournamentTeamsListDto(tournamentId) @@ -87,7 +97,7 @@ export const MatchesList = ({tournamentId}: MatchesListProps) => { function reloadAllList() { TournamentMatchesListRestAPI() - .getTournamentTeamsList(tournamentId) + .getTournamentMatch(tournamentId) .then((tournamentMatchesListDto) => setTournamentMatchesListDto(tournamentMatchesListDto)); } @@ -226,14 +236,21 @@ const returnMatchList = ( ) } -const getMatchDetailsDto = (matchId: string): Promise => MatchDetailsRestAPI() - .getTournamentTeamsList(matchId) +const getMatchDetailsDto = (matchId: string, team1: string | undefined, team2: string | undefined): Promise => MatchDetailsRestAPI() + .getTournamentMatch(matchId) .then(({firstMatchSideId, matchId, secondMatchSideId, winnerId}) => ({ matchId: matchId, firstMatchSideId: firstMatchSideId, secondMatchSideId: secondMatchSideId, winnerId: winnerId - })); + })) + .catch(() => ({ + matchId: matchId, + firstMatchSideId: team1, + secondMatchSideId: team2, + winnerId: undefined + }) +) const getPlayerProfileDto = (playerId: string): Promise => UserProfileRestApi() .getPlayerProfile(playerId) @@ -241,7 +258,7 @@ const getPlayerProfileDto = (playerId: string): Promise => Use {playerId, firstName, lastName, phoneNumber, emailAddress,})); const getTournamentTeamsListDto = (tournamentId: string): Promise => TournamentTeamsListRestApi() - .getTournamentTeamsList(tournamentId) + .getTournamentMatch(tournamentId) .then(teamsList => teamsList); const setMatchWinner = (matchId: string, winnerPlayerId: string, reloadAllList: () => void) => MatchDetailsRestAPI() diff --git a/frontend/src/restapi/match-details/MatchDetailsDto.tsx b/frontend/src/restapi/match-details/MatchDetailsDto.tsx index 7ccdcd9b..9cdf7618 100644 --- a/frontend/src/restapi/match-details/MatchDetailsDto.tsx +++ b/frontend/src/restapi/match-details/MatchDetailsDto.tsx @@ -1,6 +1,6 @@ export type MatchDetailsDto = { matchId: string, - firstMatchSideId: string, - secondMatchSideId: string, + firstMatchSideId: string |undefined, + secondMatchSideId: string |undefined, winnerId: string | undefined }; diff --git a/frontend/src/restapi/match-details/MatchDetailsRestAPI.ts b/frontend/src/restapi/match-details/MatchDetailsRestAPI.ts index 0aaadc27..00d9809b 100644 --- a/frontend/src/restapi/match-details/MatchDetailsRestAPI.ts +++ b/frontend/src/restapi/match-details/MatchDetailsRestAPI.ts @@ -22,10 +22,10 @@ export const MatchDetailsRestAPI = ( defaultConfig.baseUrl, }; return { - getTournamentTeamsList(matchId: string): Promise { + getTournamentMatch(matchId: string): Promise { return axios .get(`${currentConfig.baseUrl}/matches/${matchId}`) - .then((res) => res.data); + .then((res) => res.data) }, async postMatchWinner( diff --git a/frontend/src/restapi/tournament-details/TournamentDetailsRestApi.ts b/frontend/src/restapi/tournament-details/TournamentDetailsRestApi.ts index b42b105e..34c7265c 100644 --- a/frontend/src/restapi/tournament-details/TournamentDetailsRestApi.ts +++ b/frontend/src/restapi/tournament-details/TournamentDetailsRestApi.ts @@ -21,12 +21,12 @@ export const TournamentDetailsRestApi = ( defaultConfig.baseUrl, }; return { - getAllTournamentsDetails(): Promise { + getAllTournamentsDetails(): Promise { return axios .get( `${currentConfig.baseUrl}/tournament-details/` ) - .then(res => res.data); + .then(res => res.data) } }; }; diff --git a/frontend/src/restapi/tournament-matches-list/TournamentMatchesListRestAPI.ts b/frontend/src/restapi/tournament-matches-list/TournamentMatchesListRestAPI.ts index 1a4648cf..eefff47a 100644 --- a/frontend/src/restapi/tournament-matches-list/TournamentMatchesListRestAPI.ts +++ b/frontend/src/restapi/tournament-matches-list/TournamentMatchesListRestAPI.ts @@ -22,7 +22,7 @@ export const TournamentMatchesListRestAPI = ( defaultConfig.baseUrl, }; return { - getTournamentTeamsList( + getTournamentMatch( tournamentId: string ): Promise { return axios diff --git a/frontend/src/restapi/tournament-teams-list/TournamentTeamsListRestApi.ts b/frontend/src/restapi/tournament-teams-list/TournamentTeamsListRestApi.ts index bb6e5c4d..001f1cd7 100644 --- a/frontend/src/restapi/tournament-teams-list/TournamentTeamsListRestApi.ts +++ b/frontend/src/restapi/tournament-teams-list/TournamentTeamsListRestApi.ts @@ -22,7 +22,7 @@ export const TournamentTeamsListRestApi = ( defaultConfig.baseUrl, }; return { - getTournamentTeamsList( + getTournamentMatch( tournamentId: string ): Promise { return axios