Skip to content

Commit 976bc59

Browse files
committed
getParticipants logic moved to service
1 parent babd891 commit 976bc59

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

frontend/src/app/components/tournament/tournament.component.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,16 @@ export class TournamentComponent{
8181
}
8282

8383
getParticipants() {
84-
this.tournamentService.getTournamentTeams(this.id).subscribe(
85-
teamList => {
86-
this.participants = teamList;
87-
let isSigned = false;
88-
if (this.loginService.isLogged()) {
89-
let name = this.loginService.currentUser().name;
90-
for (let i = 0; i < teamList.length; i++){
91-
if (teamList[i].userA.name == name || teamList[i].userB.name == name){
92-
isSigned = true;
93-
}
94-
}
95-
}
96-
this.userInTournament = isSigned;
84+
let name: string
85+
if (this.loginService.isLogged()) {
86+
name = this.loginService.currentUser().name
87+
} else {
88+
name = ""
89+
}
90+
this.tournamentService.getTournamentTeams(this.id, name).subscribe(
91+
info => {
92+
this.participants = info[0];
93+
this.userInTournament = info[1];
9794
}
9895
);
9996
}

frontend/src/app/services/tournament.service.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export class TournamentService {
3838
));
3939
}
4040

41-
getTournamentTeams(id: number | string) {
41+
getTournamentTeams(id: number | string, name: string) {
4242
return this.http.get(BASE_URL + id + "/teams", { withCredentials: true }).pipe(map(
43-
response => response as Team[],
44-
error => console.error('Unexpected Error on getTournamentTeams')
43+
response => participantsMapping(response as Team[], name),
44+
_error => console.error('Unexpected Error on getTournamentTeams')
4545
))
4646
}
4747

@@ -53,10 +53,6 @@ export class TournamentService {
5353
}
5454

5555
createTournament(Tournament: Tournament) {
56-
57-
// let To : Tournament;
58-
// To={owner:"owner",tournamentName:"tournamentName",numParticipants:1,numSignedUp:0,rounds:0,about:"about",ruleset:"ruleset",
59-
// location:"location", inscriptionDate:"2022-12-16T16:00",startDate:"2022-12-16T16:00"}
6056
return this.http.post(BASE_URL, Tournament, { withCredentials: true }).subscribe((_resp: any) => {
6157
console.log("Creation Tournament: Successfully");
6258
this.router.navigate(['']);
@@ -123,16 +119,13 @@ function errorIgnore(error: any, errorNum: number, funcName: string) {
123119

124120
//Didnt work, idk. Should debug to know
125121

126-
// function participantsMapping(teamList: Team[]): [Team[], boolean] {
127-
// let isSigned = false;
128-
// if (this.loginService.isLogged()) {
129-
// let name = this.loginService.currentUser().name;
130-
// for (let i = 0; i < teamList.length; i++){
131-
// if (teamList[i].userA.name == name || teamList[i].userB.name == name){
132-
// isSigned = true;
133-
// }
134-
// }
135-
// }
136-
// return [teamList, isSigned]
137-
// }
122+
function participantsMapping(teamList: Team[], name: string): [Team[], boolean] {
123+
let isSigned = false;
124+
for (let i = 0; i < teamList.length; i++){
125+
if (teamList[i].userA.name == name || teamList[i].userB.name == name){
126+
isSigned = true;
127+
}
128+
}
129+
return [teamList, isSigned]
130+
}
138131

0 commit comments

Comments
 (0)