Skip to content

Commit

Permalink
N21-2180 Fix date for synchronized courses (#3524)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Sep 12, 2024
1 parent db6538b commit 8621572
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ const getSyncedElements = (
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;
const startDate = course.startDate
? timesHelper.formatDate(course.startDate, timesHelper.FORMAT.dateTime)
: undefined;
const untilDate = course.untilDate
? timesHelper.formatDate(course.untilDate, timesHelper.FORMAT.dateTime)
: undefined;

const selectedElements = {
teachersSelected: selectedElementIdsToString(markSelected(teachers, course.teacherIds)),
Expand Down Expand Up @@ -303,6 +307,11 @@ const editCourseHandler = (req, res, next) => {
course.name = group.name;
course.teacherIds = getUserIdsByRole(group.users, 'teacher');
course.userIds = getUserIdsByRole(group.users, 'student');

if (group.validPeriod) {
course.startDate = timesHelper.fromUTC(group.validPeriod.from);
course.untilDate = timesHelper.fromUTC(group.validPeriod.until);
}
}

const syncedElements = (course.syncedWithGroup || syncedGroupId) ? getSyncedElements(
Expand Down Expand Up @@ -837,8 +846,8 @@ router.patch('/:courseId', async (req, res, next) => {
const keys = ['teacherIds', 'substitutionIds', 'classIds', 'userIds'];
req.body = strToPropsArray(req.body, keys);

const startDate = timesHelper.dateStringToMoment(req.body.startDate);
const untilDate = timesHelper.dateStringToMoment(req.body.untilDate);
const startDate = timesHelper.dateTimeStringToMoment(req.body.startDate).utc();
const untilDate = timesHelper.dateTimeStringToMoment(req.body.untilDate).utc();

delete req.body.startDate;
if (startDate.isValid()) {
Expand Down

0 comments on commit 8621572

Please sign in to comment.