From af6048b289c2f4199b6bf81b77a838c1339d2232 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 5 Feb 2026 23:07:41 +0100 Subject: [PATCH] feat(match): normalize player lists before updating match data - Added a `normalizeList` function to filter out duplicates and invalid entries from player arrays. - Updated the match update logic to use normalized player lists for `playersReady`, `playersPlanned`, and `playersPlayed`. - Enhanced error handling in the ScheduleView to throw an error for failed match updates based on response status. --- backend/services/matchService.js | 26 ++++++++++++++++++++++---- frontend/src/views/ScheduleView.vue | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/backend/services/matchService.js b/backend/services/matchService.js index e0405cef..54e2c302 100644 --- a/backend/services/matchService.js +++ b/backend/services/matchService.js @@ -443,11 +443,29 @@ class MatchService { await checkAccess(userToken, match.clubId); - // Update player arrays + const normalizeList = (list) => { + if (!Array.isArray(list)) return null; + const seen = new Set(); + const result = []; + for (const value of list) { + if (value === null || value === undefined) continue; + const key = String(value); + if (seen.has(key)) continue; + seen.add(key); + result.push(value); + } + return result; + }; + + const readyList = normalizeList(playersReady); + const plannedList = normalizeList(playersPlanned); + const playedList = normalizeList(playersPlayed); + + // Wenn Listen übergeben wurden, gelten sie als Quelle der Wahrheit await match.update({ - playersReady: playersReady || [], - playersPlanned: playersPlanned || [], - playersPlayed: playersPlayed || [] + playersReady: readyList !== null ? readyList : (match.playersReady || []), + playersPlanned: plannedList !== null ? plannedList : (match.playersPlanned || []), + playersPlayed: playedList !== null ? playedList : (match.playersPlayed || []) }); return { diff --git a/frontend/src/views/ScheduleView.vue b/frontend/src/views/ScheduleView.vue index f7c00afd..89b017a9 100644 --- a/frontend/src/views/ScheduleView.vue +++ b/frontend/src/views/ScheduleView.vue @@ -502,6 +502,9 @@ export default { playersPlanned, playersPlayed }); + if (response.status >= 400) { + throw new Error(response?.data?.error || 'Failed to update match players'); + } console.log('[savePlayerSelection] API response:', response); // Update local match data