April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to implement the API to return the list of courses that have been created by a specific instructor, first, we will add a route in the backend to retrieve all the courses that have been created by a given user when the server receives a GET request at /api/courses/by/:userId. This route will be declared as shown next.
mern-classroom/server/routes/course.routes.js:
router.route('/api/courses/by/:userId') .get(authCtrl.requireSignin, authCtrl.hasAuthorization, courseCtrl.listByInstructor)
To process the :userId param in the route and retrieve the associated user from the database, we will utilize the userByID method in our user controller. We will add the following code to the Course routes in course.routes.js ...
Read now
Unlock full access