Update training group management and enhance UI components
This commit introduces the `TrainingGroup` model and related functionality, allowing for the management of training groups within the application. The `ClubService` is updated to automatically create preset groups upon club creation. The frontend is enhanced with new views and components, including `TrainingGroupsView` and `TrainingGroupsTab`, to facilitate the display and management of training groups. Additionally, the `MembersView` is updated to allow adding and removing members from training groups, improving the overall user experience and interactivity in managing club members and their associated training groups.
This commit is contained in:
128
backend/controllers/trainingGroupController.js
Normal file
128
backend/controllers/trainingGroupController.js
Normal file
@@ -0,0 +1,128 @@
|
||||
import trainingGroupService from '../services/trainingGroupService.js';
|
||||
import { getSafeErrorMessage } from '../utils/errorUtils.js';
|
||||
|
||||
export const getTrainingGroups = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId } = req.params;
|
||||
const groups = await trainingGroupService.getTrainingGroups(userToken, clubId);
|
||||
res.status(200).json(groups);
|
||||
} catch (error) {
|
||||
console.error('[getTrainingGroups] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Laden der Trainingsgruppen');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const createTrainingGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId } = req.params;
|
||||
const { name, sortOrder } = req.body;
|
||||
const group = await trainingGroupService.createTrainingGroup(userToken, clubId, name, sortOrder);
|
||||
res.status(201).json(group);
|
||||
} catch (error) {
|
||||
console.error('[createTrainingGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Erstellen der Trainingsgruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const updateTrainingGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, groupId } = req.params;
|
||||
const { name, sortOrder } = req.body;
|
||||
const group = await trainingGroupService.updateTrainingGroup(userToken, clubId, groupId, name, sortOrder);
|
||||
res.status(200).json(group);
|
||||
} catch (error) {
|
||||
console.error('[updateTrainingGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Aktualisieren der Trainingsgruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteTrainingGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, groupId } = req.params;
|
||||
await trainingGroupService.deleteTrainingGroup(userToken, clubId, groupId);
|
||||
res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('[deleteTrainingGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Löschen der Trainingsgruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const addMemberToGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, groupId, memberId } = req.params;
|
||||
const memberGroup = await trainingGroupService.addMemberToGroup(userToken, clubId, groupId, memberId);
|
||||
res.status(201).json(memberGroup);
|
||||
} catch (error) {
|
||||
console.error('[addMemberToGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Hinzufügen des Mitglieds zur Gruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const removeMemberFromGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, groupId, memberId } = req.params;
|
||||
await trainingGroupService.removeMemberFromGroup(userToken, clubId, groupId, memberId);
|
||||
res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('[removeMemberFromGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Entfernen des Mitglieds aus der Gruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const getMemberGroups = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, memberId } = req.params;
|
||||
const groups = await trainingGroupService.getMemberGroups(userToken, clubId, memberId);
|
||||
res.status(200).json(groups);
|
||||
} catch (error) {
|
||||
console.error('[getMemberGroups] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Laden der Gruppen des Mitglieds');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const ensurePresetGroups = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId } = req.params;
|
||||
const groups = await trainingGroupService.ensurePresetGroups(userToken, clubId);
|
||||
res.status(200).json({
|
||||
message: 'Preset-Gruppen wurden erstellt/überprüft',
|
||||
groups: groups.length
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[ensurePresetGroups] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Erstellen der Preset-Gruppen');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
export const enablePresetGroup = async (req, res) => {
|
||||
try {
|
||||
const { authcode: userToken } = req.headers;
|
||||
const { clubId, presetType } = req.params;
|
||||
const group = await trainingGroupService.enablePresetGroup(userToken, clubId, presetType);
|
||||
res.status(200).json({
|
||||
message: 'Preset-Gruppe wurde aktiviert',
|
||||
group
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[enablePresetGroup] - Error:', error);
|
||||
const msg = getSafeErrorMessage(error, 'Fehler beim Aktivieren der Preset-Gruppe');
|
||||
res.status(error.statusCode || 500).json({ error: msg });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user