Skip to content

Commit

Permalink
add group sync
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap committed Mar 14, 2024
1 parent eb07b01 commit 17bc9a5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,27 @@ const filterStudents = (ctx, s) => (
? s.filter(({ selected }) => selected) : s
);

const getUserIdsByRole = (users, role) => users.filter((u) => u.role === role).map((u) => u.id);

const selectedElementIdsToString = (arr = []) => {
const txt = arr.filter((obj) => obj.selected).map((obj) => (obj.id !== undefined ? obj.id : obj._id)).join(',');
return txt;
};

const getSyncedElementIds = (
const stringToArr = (str = '') => {
const arr = str.trim() === '' ? [] : str.split(',');
return arr;
};

const getSyncedElements = (
course,
classesAndGroups,
classAndGroupIdsOfCourse,
teachers,
substitutions,
students,
res,
syncedWithGroup,
) => {
const startDate = course.startDate ? timesHelper.formatDate(course.startDate, 'DD.MM.YYYY') : undefined;
const untilDate = course.untilDate ? timesHelper.formatDate(course.untilDate, 'DD.MM.YYYY') : undefined;
Expand All @@ -63,6 +71,7 @@ const getSyncedElementIds = (
studentsSelected: selectedElementIdsToString(filterStudents(res, markSelected(students, course.userIds))),
startDate,
untilDate,
syncedWithGroup,
};

return selectedElements;
Expand Down Expand Up @@ -318,7 +327,7 @@ const editCourseHandler = (req, res, next) => {
students: filterStudents(res, markSelected(students, course.userIds)),
scopePermissions: _scopePermissions,
schoolData: res.locals.currentSchoolData,
...syncedElementIds,
...syncedElements,
});
}
return res.render('courses/create-course', {
Expand All @@ -330,18 +339,13 @@ const editCourseHandler = (req, res, next) => {
course,
colors,
classesAndGroups: markSelected(classesAndGroups, classAndGroupIdsOfCourse),
teachers: markSelected(
teachers,
course.teacherIds,
),
substitutions: markSelected(
substitutions,
course.substitutionIds,
),
teachers: markSelected(teachers, course.teacherIds),
substitutions: markSelected(substitutions, course.substitutionIds),
students: filterStudents(res, markSelected(students, course.userIds)),
redirectUrl: req.query.redirectUrl || '/courses',
schoolData: res.locals.currentSchoolData,
pageTitle: res.$t('courses.add.headline.addCourse'),
...syncedElements,
});
}).catch(next);
};
Expand Down

0 comments on commit 17bc9a5

Please sign in to comment.