Skip to content

Commit

Permalink
adjust groups
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap committed Oct 6, 2023
1 parent be5ffdd commit faa0216
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const editCourseHandler = (req, res, next) => {
let classes = [];
if (FEATURE_GROUPS_IN_COURSE_ENABLED) {
classes = _classes.data;
groups = _classes.data.filter((c) => c.externalSourceName !== undefined);
groups = _classes.data.filter((c) => c.type === 'group');
} else {
classes = _classes.filter(
(c) => c.schoolId === res.locals.currentSchool,
Expand Down Expand Up @@ -259,7 +259,7 @@ const editCourseHandler = (req, res, next) => {
closeLabel: res.$t('global.button.cancel'),
course,
colors,
classes: markSelected(classes, course.classIds),
classes: markSelected(classes, [...course.classIds, ...course.groupIds]),
teachers: markSelected(
teachers,
course.teacherIds,
Expand Down Expand Up @@ -526,6 +526,13 @@ router.post('/', (req, res, next) => {
delete req.body[feature];
});

if (FEATURE_GROUPS_IN_COURSE_ENABLED) {
req.body.groupIds = req.body.classIds
.filter((id) => groups.some((group) => group.id === id));
req.body.classIds = req.body.classIds
.filter((id) => groups.some((group) => group.id !== id));
}

api(req)
.post('/courses/', {
json: req.body, // TODO: sanitize
Expand Down

0 comments on commit faa0216

Please sign in to comment.