This exercise is designed for you to practice chaining Promises together to manage asynchronous database calls and pass information to the view.
All code in the views has been set up for you. You only need to write code in each associated route.
- Be able to use
Knex
built in query functions instead of raw SQL - Be able to chain promises using
.then
- Be able to make multiple asynchronous database calls using
Promise.all
- Be able to pass a higher order function to
Promise.all
- Be able to extract complex database calls into smaller, well organized functions
npm install
createdb galvanize_reads_development
knex migrate:latest
knex seed:run
touch .env
nodemon
Work through the following routes one by one and in this order.
#1 SHOW
- In
authors.js
, find theGET
route for/:id
- Implement
Promises
using the pseudo code as a guide
#2 EDIT
- In
authors.js
, find theGET
route for/:id/edit
- Implement
Promises
using the pseudo code as a guide
#3 ALL
- In
authors.js
find the GET route for/
- Implement Promises using the pseudo code as a guide
- Inside
lib/helpers.js
find thegetAuthorBooks
function. - Refactor your routes so that the heavy lifting is done in this function.
- Inside your routes, call your helper function to get the job done.
Don't just copy the code from authors.js
to get this done. Challenge yourself
to think through each route again and be able to make the necessary database calls
and pass the informtion to the view.
#1 SHOW
- In
books.js
, find theGET
route for/:id
- Use
authors.js
as a reference if you need help and check the template if you don't know what variables you need to pass to locals.
#2 EDIT
- In
books.js
, find theGET
route for/:id/edit
- Use
authors.js
as a reference if you need help and check the template if you don't know what variables you need to pass to locals.
#3 ALL
- In
books.js
find the GET route for/
- Use
authors.js
as a reference if you need help and check the template if you don't know what variables you need to pass to locals.
- If you haven't done so already, refactor your routes so that the heavy
lifting is done in
lib/helpers
- See if you can refactor the other routes in
books.js
andauthors.js
and clean things up a little.
- Extract validations in
books.js
into a function - Remove the database functions at the top of
authors.js
andbooks.js
and use only functions fromqueries.js
to make database calls.
DEPLOY TO HEROKU