Skip to content

Commit

Permalink
add v3 endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap committed Oct 4, 2023
1 parent 87a7a70 commit d7f3cc2
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions controllers/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const { logger, formatError } = require('../helpers');
const timesHelper = require('../helpers/timesHelper');

const OPTIONAL_COURSE_FEATURES = ['messenger', 'videoconference'];
const FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED = Configuration.get('FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED');

const router = express.Router();
const { HOST } = require('../config/global');
Expand All @@ -27,7 +28,8 @@ const getSelectOptions = (req, service, query) => api(req).get(`/${service}`, {
}).then((data) => data.data);

const markSelected = (options, values = []) => options.map((option) => {
option.selected = values.includes(option._id);
const optionId = option.id !== undefined ? option.id : option._id;
option.selected = values.includes(optionId);
return option;
});

Expand Down Expand Up @@ -124,16 +126,22 @@ const editCourseHandler = (req, res, next) => {
action += `?redirectUrl=${req.query.redirectUrl}`;
}

const classesPromise = api(req)
.get('/classes', {
qs: {
schoolId: res.locals.currentSchool,
$populate: ['year'],
$limit: -1,
$sort: { year: -1, displayName: 1 },
},
});
// .then(data => data.data); needed when pagination is not disabled
let classesPromise;
if (FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED) {
classesPromise = api(req, { version: 'v3' })
.get('/groups/class');
} else {
classesPromise = api(req)
.get('/classes', {
qs: {
schoolId: res.locals.currentSchool,
$populate: ['year'],
$limit: -1,
$sort: { year: -1, displayName: 1 },
},
});
}

const teachersPromise = getSelectOptions(req, 'users', {
roles: ['teacher'],
$limit: false,
Expand All @@ -159,7 +167,7 @@ const editCourseHandler = (req, res, next) => {
scopePermissions,
]).then(([course, _classes, _teachers, _students, _scopePermissions]) => {
// these 3 might not change anything because hooks allow just ownSchool results by now, but to be sure:
const classes = _classes.filter(
const classes = FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED ? _classes.data : _classes.filter(
(c) => c.schoolId === res.locals.currentSchool,
).sort();
const teachers = _teachers.filter(
Expand Down Expand Up @@ -784,6 +792,11 @@ router.patch('/:courseId', async (req, res, next) => {
}

await deleteEventsForCourse(req, res, courseId);
// if(FEATURE_SHOW_GROUPS_IN_CLASS_ENABLED){
// // TODO: V3 save course
// } else {
//
// }
await api(req).patch(`/courses/${courseId}`, {
json: req.body,
});
Expand Down

0 comments on commit d7f3cc2

Please sign in to comment.