Last Sync: 2022-08-30 15:00:04
This commit is contained in:
parent
196b9f4112
commit
242157ae84
1 changed files with 15 additions and 1 deletions
|
@ -80,7 +80,7 @@ const courseSchema = new mongoose.Schema({
|
||||||
With this established we can remove our local array as we are ready to start getting our data from the database:
|
With this established we can remove our local array as we are ready to start getting our data from the database:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
const Course = new mongoose.model('Course', courseSchema);
|
const Course = mongoose.model('Course', courseSchema);
|
||||||
|
|
||||||
- const courses = [
|
- const courses = [
|
||||||
- {
|
- {
|
||||||
|
@ -191,3 +191,17 @@ router.delete("/:id", (req, res) => {
|
||||||
res.send(course);
|
res.send(course);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```diff
|
||||||
|
|
||||||
|
router.delete("/:id", async (req, res) => {
|
||||||
|
const courseToDelete = await Course.findByIdAndRemove(req.params.id)
|
||||||
|
|
||||||
|
if (!course) return res.status(404).send("A course with the given ID was not found");
|
||||||
|
|
||||||
|
- courses.indexOf(course);
|
||||||
|
- courses.splice(index, 1);
|
||||||
|
|
||||||
|
res.send(course);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue