Update server port and enhance participant management features
Changed the server port from 3000 to 3005 for local development. Enhanced the participant management functionality by adding a new endpoint to update participant group assignments, including error handling for non-existent participants. Updated the participant model to include a groupId reference, and modified the participant retrieval logic to include group information. Additionally, improved the frontend API client to accommodate the new backend structure and added filtering options in the MembersView for better user experience.
This commit is contained in:
@@ -4,7 +4,10 @@ import { devLog } from '../utils/logger.js';
|
||||
export const getParticipants = async (req, res) => {
|
||||
try {
|
||||
const { dateId } = req.params;
|
||||
const participants = await Participant.findAll({ where: { diaryDateId: dateId } });
|
||||
const participants = await Participant.findAll({
|
||||
where: { diaryDateId: dateId },
|
||||
attributes: ['id', 'diaryDateId', 'memberId', 'groupId', 'notes', 'createdAt', 'updatedAt']
|
||||
});
|
||||
res.status(200).json(participants);
|
||||
} catch (error) {
|
||||
devLog(error);
|
||||
@@ -12,6 +15,32 @@ export const getParticipants = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const updateParticipantGroup = async (req, res) => {
|
||||
try {
|
||||
const { dateId, memberId } = req.params;
|
||||
const { groupId } = req.body;
|
||||
|
||||
const participant = await Participant.findOne({
|
||||
where: {
|
||||
diaryDateId: dateId,
|
||||
memberId: memberId
|
||||
}
|
||||
});
|
||||
|
||||
if (!participant) {
|
||||
return res.status(404).json({ error: 'Teilnehmer nicht gefunden' });
|
||||
}
|
||||
|
||||
participant.groupId = groupId || null;
|
||||
await participant.save();
|
||||
|
||||
res.status(200).json(participant);
|
||||
} catch (error) {
|
||||
devLog(error);
|
||||
res.status(500).json({ error: 'Fehler beim Aktualisieren der Teilnehmer-Gruppenzuordnung' });
|
||||
}
|
||||
};
|
||||
|
||||
export const addParticipant = async (req, res) => {
|
||||
try {
|
||||
const { diaryDateId, memberId } = req.body;
|
||||
|
||||
9
backend/migrations/add_group_id_to_participants.sql
Normal file
9
backend/migrations/add_group_id_to_participants.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Migration: Add group_id to participants table
|
||||
-- This allows assigning participants to groups for training organization
|
||||
|
||||
ALTER TABLE participants
|
||||
ADD COLUMN group_id INTEGER NULL REFERENCES "group"(id) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- Add index for better query performance
|
||||
CREATE INDEX IF NOT EXISTS idx_participants_group_id ON participants(group_id);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { DataTypes } from 'sequelize';
|
||||
import sequelize from '../database.js';
|
||||
import Member from './Member.js';
|
||||
import DiaryDate from './DiaryDates.js';
|
||||
import Group from './Group.js';
|
||||
import { encryptData, decryptData } from '../utils/encrypt.js';
|
||||
|
||||
const Participant = sequelize.define('Participant', {
|
||||
@@ -27,6 +28,16 @@ const Participant = sequelize.define('Participant', {
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
groupId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: Group,
|
||||
key: 'id'
|
||||
},
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE'
|
||||
},
|
||||
notes: {
|
||||
type: DataTypes.STRING(4096),
|
||||
allowNull: true,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { getParticipants, addParticipant, removeParticipant } from '../controllers/participantController.js';
|
||||
import { getParticipants, addParticipant, removeParticipant, updateParticipantGroup } from '../controllers/participantController.js';
|
||||
import { authenticate } from '../middleware/authMiddleware.js';
|
||||
|
||||
const router = express.Router();
|
||||
@@ -7,5 +7,6 @@ const router = express.Router();
|
||||
router.get('/:dateId', authenticate, getParticipants);
|
||||
router.post('/add', authenticate, addParticipant);
|
||||
router.post('/remove', authenticate, removeParticipant);
|
||||
router.put('/:dateId/:memberId/group', authenticate, updateParticipantGroup);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -43,7 +43,7 @@ import permissionRoutes from './routes/permissionRoutes.js';
|
||||
import schedulerService from './services/schedulerService.js';
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
const port = process.env.PORT || 3005;
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
Reference in New Issue
Block a user