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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user