Skip to content

Week 3 homework exercise#17

Open
drubini90 wants to merge 1 commit intopce-uw-jscript400:masterfrom
drubini90:master
Open

Week 3 homework exercise#17
drubini90 wants to merge 1 commit intopce-uw-jscript400:masterfrom
drubini90:master

Conversation

@drubini90
Copy link

No description provided.

const author = book.authors.id(req.params.id).remove();
await book.save();
res.json({ status, author });
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must export the router at the bottom of this page :
module.exports = router;

// Routes
app.use('/api/books', require('./api/routes/books'))
app.use("/api/books", require("./api/routes/books"));
app.use("api/books/bookId/authors", require("./api/routes/books.authors"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be :bookId to pull out as a param

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need "/" at beginning of route.

router.delete("/:authorId", async (req, res, next) => {
const status = 200;
const book = await Books.findById(req.params.bookId);
const author = book.authors.id(req.params.id).remove();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params should match what you use in the route. so
req.params.authorId

router.put("/:authorId", async (req, res, next) => {
const status = 200;
const book = await Books.findById(req.params.bookId);
const author = book.author.id(req.params.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should match authorId

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be book.authors.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants