April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to implement a backend API that will query the Enrollments collection in the database to calculate the stats for a specific course, we first need to declare a GET route at '/api/enrollment/stats/:courseId', as shown in the following code.
mern-classroom/server/routes/enrollment.routes.js
router.route('/api/enrollment/stats/:courseId') .get(enrollmentCtrl.enrollmentStats)
A GET request at this URL will return a stats object containing the total enrollments and total completions for the course, as identified by the courseId provided in the URL parameter. This implementation is defined in the enrollmentStats controller method, as shown in the following code.
mern-classroom/server/controllers/enrollment.controller.js ...
Read now
Unlock full access