April 2020
Intermediate to advanced
716 pages
18h 55m
English
The list of enrollments API will take a GET request and query the Enrollments collection in order to find enrollments that have a student reference that matches with the user who is currently signed in. To implement this API, we will first declare the GET route for '/api/enrollment/enrolled', as shown in the following code:
mern-classroom/server/routes/enrollment.routes.js
router.route('/api/enrollment/enrolled') .get(authCtrl.requireSignin, enrollmentCtrl.listEnrolled)
A GET request to this route will invoke the listEnrolled controller method, which will query the database and return the results in the response to the client. The listEnrolled method is defined as follows:
mern-classroom/server/controllers/enrollment.controller.js ...