From 5605cd61896343d04796a6a92f478ce70ec64a12 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 5 Feb 2026 22:58:44 +0100 Subject: [PATCH] feat(match): add endpoint to retrieve active players for a club - Implemented a new controller method `getMatchPlayers` to fetch active members of a specified club, returning their details. - Updated the match routes to include a new GET route for retrieving players by club ID. - Modified the ScheduleView to include the current club ID when updating player information. --- backend/controllers/matchController.js | 18 ++++++++++++++++++ backend/routes/matchRoutes.js | 3 ++- frontend/src/views/ScheduleView.vue | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/controllers/matchController.js b/backend/controllers/matchController.js index 05476740..868cbaf6 100644 --- a/backend/controllers/matchController.js +++ b/backend/controllers/matchController.js @@ -145,3 +145,21 @@ export const getPlayerMatchStats = async (req, res) => { }); } }; + +export const getMatchPlayers = async (req, res) => { + try { + const { clubId } = req.params; + if (!clubId) { + return res.status(400).json({ error: 'Club-ID fehlt' }); + } + const Member = (await import('../models/Member.js')).default; + const members = await Member.findAll({ + where: { clubId: clubId, active: true }, + attributes: ['id', 'firstName', 'lastName', 'gender'] + }); + return res.status(200).json(members); + } catch (error) { + console.error('Error retrieving match players:', error); + return res.status(500).json({ error: 'Failed to retrieve match players' }); + } +}; diff --git a/backend/routes/matchRoutes.js b/backend/routes/matchRoutes.js index a2bd09e7..30bf156a 100644 --- a/backend/routes/matchRoutes.js +++ b/backend/routes/matchRoutes.js @@ -1,5 +1,5 @@ import express from 'express'; -import { uploadCSV, getLeaguesForCurrentSeason, getMatchesForLeagues, getMatchesForLeague, getLeagueTable, fetchLeagueTableFromMyTischtennis, updateMatchPlayers, getPlayerMatchStats } from '../controllers/matchController.js'; +import { uploadCSV, getLeaguesForCurrentSeason, getMatchesForLeagues, getMatchesForLeague, getLeagueTable, fetchLeagueTableFromMyTischtennis, updateMatchPlayers, getPlayerMatchStats, getMatchPlayers } from '../controllers/matchController.js'; import { authenticate } from '../middleware/authMiddleware.js'; import { authorize } from '../middleware/authorizationMiddleware.js'; import multer from 'multer'; @@ -14,6 +14,7 @@ router.get('/leagues/:clubId/matches/:leagueId', authenticate, authorize('schedu router.get('/leagues/:clubId/matches', authenticate, authorize('schedule', 'read'), getMatchesForLeagues); router.get('/leagues/:clubId/table/:leagueId', authenticate, authorize('schedule', 'read'), getLeagueTable); router.post('/leagues/:clubId/table/:leagueId/fetch', authenticate, authorize('mytischtennis', 'write'), fetchLeagueTableFromMyTischtennis); +router.get('/:clubId/players', authenticate, authorize('schedule', 'read'), getMatchPlayers); router.patch('/:matchId/players', authenticate, authorize('schedule', 'write'), updateMatchPlayers); router.get('/leagues/:clubId/stats/:leagueId', authenticate, authorize('schedule', 'read'), getPlayerMatchStats); diff --git a/frontend/src/views/ScheduleView.vue b/frontend/src/views/ScheduleView.vue index a39f0fb0..f7c00afd 100644 --- a/frontend/src/views/ScheduleView.vue +++ b/frontend/src/views/ScheduleView.vue @@ -497,6 +497,7 @@ export default { try { const response = await apiClient.patch(`/matches/${match.id}/players`, { + clubId: this.currentClub, playersReady, playersPlanned, playersPlayed