April 2020
Intermediate to advanced
716 pages
18h 55m
English
When a user chooses to enroll in a course, we will create a new enrollment and store it in the backend. To implement this feature, we need to define a create enrollment API on the server, by first declaring a route that accepts a POST request at '/api/enrollment/new/:courseId', as shown in the following code:
mern-classroom/server/routes/enrollment.routes.js:
router.route('/api/enrollment/new/:courseId') .get(authCtrl.requireSignin, enrollmentCtrl.findEnrollment, enrollmentCtrl.create)router.param('courseId', courseCtrl.courseByID)
This route takes the course ID as a parameter in the URL. Hence, we also add the courseByID controller method from the course controllers in order to process this parameter and retrieve ...