fix(tournament): improve match identification logic for player IDs
- Updated the getMatchLiveResult and handleMatchClick methods to handle potential null values for player IDs, ensuring robust match identification. - Refactored ID retrieval logic to use optional chaining and fallback values, enhancing code readability and preventing errors when player data is incomplete.
This commit is contained in:
@@ -346,11 +346,14 @@ export default {
|
||||
return classItem ? Boolean(classItem.isDoubles) : false;
|
||||
},
|
||||
getMatchLiveResult(player1Id, player2Id, groupId) {
|
||||
const id1 = (m) => m.player1?.id ?? m.player1Id;
|
||||
const id2 = (m) => m.player2?.id ?? m.player2Id;
|
||||
const match = this.matches.find(m =>
|
||||
m.round === 'group' &&
|
||||
m.groupId === groupId &&
|
||||
((m.player1.id === player1Id && m.player2.id === player2Id) ||
|
||||
(m.player1.id === player2Id && m.player2.id === player1Id))
|
||||
id1(m) != null && id2(m) != null &&
|
||||
((id1(m) === player1Id && id2(m) === player2Id) ||
|
||||
(id1(m) === player2Id && id2(m) === player1Id))
|
||||
);
|
||||
|
||||
if (!match) return null;
|
||||
@@ -410,13 +413,13 @@ export default {
|
||||
const playerMatches = this.matches.filter(m =>
|
||||
m.round === 'group' &&
|
||||
m.groupId === groupId &&
|
||||
(m.player1.id === player.id || m.player2.id === player.id) &&
|
||||
((m.player1?.id ?? m.player1Id) === player.id || (m.player2?.id ?? m.player2Id) === player.id) &&
|
||||
!m.isFinished &&
|
||||
m.tournamentResults && m.tournamentResults.length > 0
|
||||
);
|
||||
|
||||
playerMatches.forEach(match => {
|
||||
const isPlayer1 = match.player1.id === player.id;
|
||||
const isPlayer1 = (match.player1?.id ?? match.player1Id) === player.id;
|
||||
match.tournamentResults.forEach(result => {
|
||||
if (isPlayer1) {
|
||||
if (result.pointsPlayer1 > result.pointsPlayer2) {
|
||||
@@ -457,12 +460,15 @@ export default {
|
||||
handleMatchClick(player1Id, player2Id, groupId) {
|
||||
// Highlight das Match
|
||||
this.$emit('highlight-match', player1Id, player2Id, groupId);
|
||||
// Finde das Match und gehe zum Ergebnistab
|
||||
// Finde das Match und gehe zum Ergebnistab (player1/player2 können null sein, wenn Spieler gelöscht)
|
||||
const id1 = (m) => m.player1?.id ?? m.player1Id;
|
||||
const id2 = (m) => m.player2?.id ?? m.player2Id;
|
||||
const match = this.matches.find(m =>
|
||||
m.round === 'group' &&
|
||||
m.groupId === groupId &&
|
||||
((m.player1.id === player1Id && m.player2.id === player2Id) ||
|
||||
(m.player1.id === player2Id && m.player2.id === player1Id))
|
||||
id1(m) != null && id2(m) != null &&
|
||||
((id1(m) === player1Id && id2(m) === player2Id) ||
|
||||
(id1(m) === player2Id && id2(m) === player1Id))
|
||||
);
|
||||
if (match) {
|
||||
this.$emit('go-to-match', match.id);
|
||||
|
||||
Reference in New Issue
Block a user