fac22 / week2-ABES

PostgreSQL Database project
1 stars 0 forks source link

Async handling #23

Open oliverjam opened 3 years ago

oliverjam commented 3 years ago

https://github.com/fac22/week2-ABES/blob/2b46c229a651c0ef3a2d5b642205203226c1c97a/routes/review.js#L31-L49

(btw it's cool that you started with mocked hard-coded data for this to get it working, then moved it into the DB ✨)

Right now you redirect to the home page without waiting for the actual creation of the DB rows to be complete. This probably works because the redirect + loading the new page takes longer than the database queries, but this isn't guaranteed. If the query took a bit longer you'd occasionally end up on the home page without the new stuff yet.

You need to wait promises to resolve before sending any response from your server (even a redirect).