Skip to content

Commit

Permalink
Frontend | Adjust matches list for backend endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrRynio authored Apr 14, 2021
1 parent 3bdda83 commit 3716666
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
29 changes: 23 additions & 6 deletions frontend/src/components/organisms/MatchesList/MatchesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export const MatchesList = ({tournamentId}: MatchesListProps) => {
const [playersProfilesListDto, setPlayersProfilesListDto] = React.useState<PlayerProfileDto[] | undefined>(undefined);
const [matchesList, setMatchesList] = React.useState<MatchItemType[] | undefined>();


console.log("tuuuu");
console.log(expanded);
console.log(tournamentMatchesListDto);
console.log(matchesDetailsListDto);
console.log(tournamentTeamsListDto);
console.log(playersProfilesListDto);
console.log(matchesList);


useEffect(() => {
reloadAllList()
}, [tournamentId]);
Expand All @@ -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)
Expand Down Expand Up @@ -87,7 +97,7 @@ export const MatchesList = ({tournamentId}: MatchesListProps) => {

function reloadAllList() {
TournamentMatchesListRestAPI()
.getTournamentTeamsList(tournamentId)
.getTournamentMatch(tournamentId)
.then((tournamentMatchesListDto) => setTournamentMatchesListDto(tournamentMatchesListDto));
}

Expand Down Expand Up @@ -226,22 +236,29 @@ const returnMatchList = (
)
}

const getMatchDetailsDto = (matchId: string): Promise<MatchDetailsDto> => MatchDetailsRestAPI()
.getTournamentTeamsList(matchId)
const getMatchDetailsDto = (matchId: string, team1: string | undefined, team2: string | undefined): Promise<MatchDetailsDto> => 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<PlayerProfileDto> => UserProfileRestApi()
.getPlayerProfile(playerId)
.then(({emailAddress, firstName, lastName, phoneNumber, playerId}) => (
{playerId, firstName, lastName, phoneNumber, emailAddress,}));

const getTournamentTeamsListDto = (tournamentId: string): Promise<TournamentTeamsListDto> => TournamentTeamsListRestApi()
.getTournamentTeamsList(tournamentId)
.getTournamentMatch(tournamentId)
.then(teamsList => teamsList);

const setMatchWinner = (matchId: string, winnerPlayerId: string, reloadAllList: () => void) => MatchDetailsRestAPI()
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/restapi/match-details/MatchDetailsDto.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type MatchDetailsDto = {
matchId: string,
firstMatchSideId: string,
secondMatchSideId: string,
firstMatchSideId: string |undefined,
secondMatchSideId: string |undefined,
winnerId: string | undefined
};
4 changes: 2 additions & 2 deletions frontend/src/restapi/match-details/MatchDetailsRestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const MatchDetailsRestAPI = (
defaultConfig.baseUrl,
};
return {
getTournamentTeamsList(matchId: string): Promise<MatchDetailsDto> {
getTournamentMatch(matchId: string): Promise<MatchDetailsDto> {
return axios
.get<MatchDetailsDto>(`${currentConfig.baseUrl}/matches/${matchId}`)
.then((res) => res.data);
.then((res) => res.data)
},

async postMatchWinner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export const TournamentDetailsRestApi = (
defaultConfig.baseUrl,
};
return {
getAllTournamentsDetails(): Promise<TournamentDetailsDto[]> {
getAllTournamentsDetails(): Promise<TournamentDetailsDto[] > {
return axios
.get<TournamentDetailsDto[]>(
`${currentConfig.baseUrl}/tournament-details/`
)
.then(res => res.data);
.then(res => res.data)
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const TournamentMatchesListRestAPI = (
defaultConfig.baseUrl,
};
return {
getTournamentTeamsList(
getTournamentMatch(
tournamentId: string
): Promise<TournamentMatchesListDto> {
return axios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const TournamentTeamsListRestApi = (
defaultConfig.baseUrl,
};
return {
getTournamentTeamsList(
getTournamentMatch(
tournamentId: string
): Promise<TournamentTeamsListDto> {
return axios
Expand Down

1 comment on commit 3716666

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://wkps.netlify.app as production
🚀 Deployed on https://607769f31cb1c55ffc7a41f4--wkps.netlify.app

Please sign in to comment.