modif api
This commit is contained in:
parent
e061b9d1c0
commit
fe5212bd97
6 changed files with 56 additions and 7 deletions
|
|
@ -59,8 +59,14 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||
|
||||
this.loadRelatedEntities(this.latestMatch);
|
||||
|
||||
if (this.latestMatch.state === MatchState.NOT_STARTED) {
|
||||
console.log(this.latestMatch.state);
|
||||
const stateEnum = parseMatchState(
|
||||
this.latestMatch.state as unknown as string
|
||||
);
|
||||
|
||||
if (stateEnum !== undefined) {
|
||||
this.latestMatch.state = stateEnum; // Remplacement par l'enum numérique
|
||||
} else {
|
||||
console.warn('État de match inconnu :', this.latestMatch.state);
|
||||
}
|
||||
|
||||
if (this.latestMatch.state === MatchState.NOT_STARTED) {
|
||||
|
|
@ -155,3 +161,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||
return this.timeUntilMatch;
|
||||
}
|
||||
}
|
||||
|
||||
function parseMatchState(stateStr: string): MatchState | undefined {
|
||||
return MatchState[stateStr as keyof typeof MatchState];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
<div class="text-center">
|
||||
<ng-container
|
||||
*ngIf="
|
||||
authService.isAuthenticated() && match.state != 2;
|
||||
authService.isAuthenticated() && match.state != 1;
|
||||
else displayScores
|
||||
"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -41,6 +41,16 @@ export class MatchesIdComponent implements OnInit {
|
|||
if (match) {
|
||||
this.match = match;
|
||||
|
||||
const stateEnum = parseMatchState(
|
||||
this.match.state as unknown as string
|
||||
);
|
||||
|
||||
if (stateEnum !== undefined) {
|
||||
this.match.state = stateEnum;
|
||||
} else {
|
||||
console.warn('État de match inconnu :', this.match.state);
|
||||
}
|
||||
|
||||
this.playerService.getPlayerById(match.player1ID).subscribe((res1) => {
|
||||
this.player1 = res1.data;
|
||||
});
|
||||
|
|
@ -66,8 +76,16 @@ export class MatchesIdComponent implements OnInit {
|
|||
saveScores(): void {
|
||||
if (this.match) {
|
||||
this.matchService.updateMatch(this.match.id, {
|
||||
refereeID: this.match.refereeID,
|
||||
player1ID: this.match.player1ID,
|
||||
score1: this.match.score1,
|
||||
player2ID: this.match.player2ID,
|
||||
score2: this.match.score2,
|
||||
country: this.match.country,
|
||||
city: this.match.city,
|
||||
weapon: this.match.weapon,
|
||||
date: this.match.date,
|
||||
state: this.match.state,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -87,11 +105,11 @@ export class MatchesIdComponent implements OnInit {
|
|||
|
||||
getMatchStateColor(state: MatchState): string {
|
||||
switch (state) {
|
||||
case MatchState.NOT_STARTED:
|
||||
case 2:
|
||||
return 'secondary';
|
||||
case MatchState.ONGOING:
|
||||
case 0:
|
||||
return 'warning';
|
||||
case MatchState.OVER:
|
||||
case 1:
|
||||
return 'success';
|
||||
default:
|
||||
return 'light';
|
||||
|
|
@ -157,3 +175,7 @@ export class MatchesIdComponent implements OnInit {
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
function parseMatchState(stateStr: string): MatchState | undefined {
|
||||
return MatchState[stateStr as keyof typeof MatchState];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ export class MatchesComponent {
|
|||
private router: Router
|
||||
) {}
|
||||
|
||||
parseMatchState(stateStr: string): MatchState | undefined {
|
||||
return MatchState[stateStr as keyof typeof MatchState];
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.playerService.getPlayers().subscribe({
|
||||
next: (response) => {
|
||||
|
|
@ -45,6 +49,15 @@ export class MatchesComponent {
|
|||
next: (response) => {
|
||||
if (response) {
|
||||
this.matches = response;
|
||||
this.matches = this.matches.map((match) => {
|
||||
const enumState = this.parseMatchState(
|
||||
match.state as unknown as string
|
||||
);
|
||||
return {
|
||||
...match,
|
||||
state: enumState !== undefined ? enumState : match.state,
|
||||
};
|
||||
});
|
||||
} else {
|
||||
console.warn(
|
||||
'[MatchesComponent] Erreur lors du chargement des matchs'
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export class ApiService {
|
|||
}
|
||||
|
||||
put<T>(endpoint: string, body: any): Observable<ApiResponse<T>> {
|
||||
console.log(endpoint, body);
|
||||
return this.http
|
||||
.put<ApiResponse<T>>(`${this.baseUrl}/${endpoint}`, body)
|
||||
.pipe(catchError(this.handleError));
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ export class MatchesService {
|
|||
updatedData: Partial<Matches>
|
||||
): Observable<ApiResponse<Matches>> {
|
||||
console.log(`[MatchesService] PUT update match ID: ${id}`, updatedData);
|
||||
return this.api.put<Matches>(`${this.endpoint}/${id}`, updatedData);
|
||||
return this.api.put<Matches>(
|
||||
`${this.endpoint}/update-match/${id}`,
|
||||
updatedData
|
||||
);
|
||||
}
|
||||
|
||||
deleteMatch(id: number): Observable<ApiResponse<boolean>> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue