cant get authors to work still#25
Conversation
| const router = require('express').Router({mergeParams: true}) | ||
| const Books = require('../models/books') | ||
|
|
||
|
|
There was a problem hiding this comment.
Because of how you defined your routes in the books.js route file most of the code in this file will never be called. See my other comment.
There was a problem hiding this comment.
O jeez! That saved me, I felt like I was going crazy! Thank you for your help!
api/routes/books.js
Outdated
| }) | ||
|
|
||
| router.put('/:id', (req, res, next) => { | ||
| router.get('/:bookId/authors/:id', async (req, res, next) => { |
There was a problem hiding this comment.
By defining this route in books.js this 'get' will be executed while the 'get' in books.authors.js line 24 will never be called because this is matched first. It's ok to set up routes this way but be aware that this will happen.
api/routes/books.js
Outdated
| }) | ||
|
|
||
| router.delete('/:id', (req, res, next) => { | ||
| router.put('/:bookId/authors/:id', async (req, res, next) => { |
There was a problem hiding this comment.
Same idea here, authors/:id will execute here instead of books.authors.js
| res.json({ status, author }) | ||
| }) | ||
|
|
||
| router.put('/:id', async (req, res, next) => { |
There was a problem hiding this comment.
This code looks good but is never running because of the issue posted below.
I apologize for this being late. I was sick over the weekend and last week. I am trying to catch up.