From 5bdc5c8216a7c926031ebf2a4741cad70540fb39 Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Wed, 6 Nov 2024 09:20:39 +0100 Subject: [PATCH] Fixed group activities and added collapsing for general settings --- backend/controllers/groupController.js | 15 ++++- backend/routes/groupRoutes.js | 9 ++- backend/services/diaryDateActivityService.js | 2 +- backend/services/diaryService.js | 2 +- backend/services/groupService.js | 19 ++++++ frontend/src/views/DiaryView.vue | 63 +++++++++++++++++--- 6 files changed, 95 insertions(+), 15 deletions(-) diff --git a/backend/controllers/groupController.js b/backend/controllers/groupController.js index b2d0aba..ec5c1f2 100644 --- a/backend/controllers/groupController.js +++ b/backend/controllers/groupController.js @@ -26,4 +26,17 @@ const getGroups = async(req, res) => { } } -export { addGroup, getGroups }; \ No newline at end of file +const changeGroup = async(req, res) => { + try { + const { authcode: userToken } = req.headers; + const { groupId } = req.params; + const { clubid: clubId, dateid: dateId, name, lead } = req.body; + const result = await groupService.changeGroup(userToken, groupId, clubId, dateId, name, lead); + res.status(200).json(result); + } catch (error) { + console.error('[changeGroup] - Error:', error); + res.status(error.statusCode || 500).json({ error: error.message }); + } +} + +export { addGroup, getGroups, changeGroup}; \ No newline at end of file diff --git a/backend/routes/groupRoutes.js b/backend/routes/groupRoutes.js index 11eee8c..5cc30d6 100644 --- a/backend/routes/groupRoutes.js +++ b/backend/routes/groupRoutes.js @@ -1,10 +1,13 @@ import express from 'express'; import { authenticate } from '../middleware/authMiddleware.js'; -import { addGroup, getGroups } from '../controllers/groupController.js'; +import { addGroup, getGroups, changeGroup } from '../controllers/groupController.js'; const router = express.Router(); -router.post('/', authenticate, addGroup); -router.get('/:clubId/:dateId', authenticate, getGroups); +router.use(authenticate); + +router.post('/', addGroup); +router.get('/:clubId/:dateId', getGroups); +router.put('/:groupId', changeGroup); export default router; diff --git a/backend/services/diaryDateActivityService.js b/backend/services/diaryDateActivityService.js index d34a7d4..9719e5e 100644 --- a/backend/services/diaryDateActivityService.js +++ b/backend/services/diaryDateActivityService.js @@ -144,7 +144,7 @@ class DiaryDateActivityService { diaryDateId, isTimeblock: true, }, - order: [['order_id', 'ASC']], + order: [['order_id', 'DESC']], limit: 1 }); if (!diaryDateActivity) { diff --git a/backend/services/diaryService.js b/backend/services/diaryService.js index 7136132..0b97255 100644 --- a/backend/services/diaryService.js +++ b/backend/services/diaryService.js @@ -22,7 +22,7 @@ class DiaryService { { model: DiaryNote, as: 'diaryNotes' }, // Der Alias für DiaryNote ist korrekt { model: DiaryTag, as: 'diaryTags' }, // Hier muss der Alias auf 'diaryTags' geändert werden ], - order: [['date', 'ASC'], ['trainingStart', 'ASC']] + order: [['date', 'DESC'], ['trainingStart', 'ASC']] }); return dates; } diff --git a/backend/services/groupService.js b/backend/services/groupService.js index d4ec0b8..f03afab 100644 --- a/backend/services/groupService.js +++ b/backend/services/groupService.js @@ -38,6 +38,25 @@ class GroupService { }); return groups; } + + async changeGroup(userToken, groupId, clubId, dateId, name, lead) { + console.log("changeGroup: ", groupId, clubId, dateId, name, lead); + await checkAccess(userToken, clubId); + await this.checkDiaryDateToClub(clubId, dateId); + const group = await Group.findOne({ + where: { + id: groupId, + diaryDateId: dateId + } + }); + if (!group) { + throw new HttpError('Gruppe nicht gefunden oder passt nicht zum angegebenen Datum und Verein', 404); + } + group.name = name; + group.lead = lead; + await group.save(); + return group; + } } export default new GroupService(); \ No newline at end of file diff --git a/frontend/src/views/DiaryView.vue b/frontend/src/views/DiaryView.vue index 3880284..9c2e4e6 100644 --- a/frontend/src/views/DiaryView.vue +++ b/frontend/src/views/DiaryView.vue @@ -5,7 +5,8 @@ @@ -28,9 +29,11 @@ +
-

Trainingszeiten bearbeiten

-
+

Trainingszeiten bearbeiten {{ showGeneralData ? + '-' : '+' }}

+
@@ -45,16 +48,25 @@
-

Gruppenverwaltung

-
+

Gruppenverwaltung

+

Vorhandene Gruppen

  • - {{ group.name }} (Leiter: {{ group.lead }}) + {{ group.name + }} + + (Leiter: {{ + group.lead }}) +
-
+

Neue Gruppe erstellen

@@ -93,7 +105,8 @@ item.activity }} {{ item.groupActivity ? item.groupActivity.name : '' }} - {{ item.durationText }} / {{ item.duration }} + {{ item.durationText }} / {{ + item.duration }}