From 9d5d75617d43516e7a4e99f12ede1e74f5e0d04a Mon Sep 17 00:00:00 2001 From: Nikki Pham Date: Fri, 17 Mar 2023 12:53:00 +1100 Subject: [PATCH] fixed missing add user id --- controllers/workout_controller.js | 4 ++-- db/schema.sql | 1 + latest.dump | 0 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 latest.dump diff --git a/controllers/workout_controller.js b/controllers/workout_controller.js index 42e1613..ddb2357 100644 --- a/controllers/workout_controller.js +++ b/controllers/workout_controller.js @@ -159,8 +159,8 @@ router.post("/workouts", (req, res) => { res.redirect("/workouts/new") return } else { - const sql = "INSERT INTO workouts (name, workout_date) VALUES ($1, $2) returning workout_id;" - db.query(sql, [req.body.name, req.body.workout_date], (err, dbRes) => { + const sql = "INSERT INTO workouts (name, workout_date, user_id) VALUES ($1, $2, $3) returning workout_id;" + db.query(sql, [req.body.name, req.body.workout_date, req.session.userId], (err, dbRes) => { // add later req.session.userId or res.locals.currentUser.id res.redirect(`/workouts/${dbRes.rows[0].workout_id}`) }) diff --git a/db/schema.sql b/db/schema.sql index 19d0633..7601d00 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -4,6 +4,7 @@ DROP TABLE workouts; DROP TABLE exercises; DROP TABLE workout_exercise_junction; DROP TABLE log_workout_entries; +DROP TABLE users; CREATE TABLE workouts ( workout_id SERIAL PRIMARY KEY, diff --git a/latest.dump b/latest.dump new file mode 100644 index 0000000..e69de29