April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to implement a backend API that takes a request to delete a specified course from the database, we will first define a DELETE route as shown in the following code.
mern-classroom/server/routes/course.routes.js:
router.route('/api/courses/:courseId') .delete(authCtrl.requireSignin, courseCtrl.isInstructor, courseCtrl.remove)
This DELETE route takes the course ID as a URL parameter and checks if the current user is signed in and authorized to perform this delete, before proceeding to the remove controller method, which is defined in the following code.
mern-classroom/server/controllers/course.controller.js:
const remove = async (req, res) => { try { let course = req.course let deleteCourse = await course.remove() ...