From 57d39ab327e43e567f481de6b4d695d2ab5efd56 Mon Sep 17 00:00:00 2001 From: Nikki Pham Date: Fri, 17 Mar 2023 13:35:49 +1100 Subject: [PATCH] safeguarded the new workout --- controllers/user_controller.js | 9 ++++++--- latest.dump | Bin 0 -> 12610 bytes views/user_workouts.ejs | 13 ++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/controllers/user_controller.js b/controllers/user_controller.js index 164ec7c..43992d4 100644 --- a/controllers/user_controller.js +++ b/controllers/user_controller.js @@ -44,7 +44,9 @@ router.get("/users/workouts", ensureLoggedIn, (req, res) => { router.get("/users/:userid/workouts", ensureLoggedIn, (req, res) => { const sql = "SELECT *, TO_CHAR(workout_date, 'FMMonth DD, YYYY') FROM workouts WHERE user_id = $1 ORDER BY workout_date DESC;" // console.log(req.session.userId, "session userId"); - db.query(sql, [req.session.userId], (err, dbRes) => { + const currentUserSessionId = req.session.userId + const workoutUserId = req.params.userid + db.query(sql, [workoutUserId], (err, dbRes) => { const workouts = dbRes.rows // console.log("workouts",workouts); const sql2 = "SELECT * FROM workout_exercise_junction JOIN exercises ON workout_exercise_junction.exercise_id = exercises.exercise_id;" @@ -55,7 +57,7 @@ router.get("/users/:userid/workouts", ensureLoggedIn, (req, res) => { const sql3 = "SELECT * FROM users where user_id = $1" db.query(sql3, [req.params.userid], (err, dbUsersRes) => { const user = dbUsersRes.rows[0] - res.render("user_workouts", { workouts, exercisesInWorkouts, user }) + res.render("user_workouts", { workouts, exercisesInWorkouts, user, currentUserSessionId }) }) @@ -122,7 +124,8 @@ router.post("/users", (req, res) => { const sql2 = "INSERT INTO users (email, username, full_name, password_digest, profile_photo) VALUES ($1, $2, $3, $4, $5) RETURNING user_id;" db.query(sql2, [email, username, req.body.full_name, digestedPassword, default_profile_picture_url], (err, insertRes) => { req.session.userId = insertRes.rows[0].user_id - res.redirect("/") + + res.redirect(`/users/${insertRes.rows[0].user_id}`) }) }) }) diff --git a/latest.dump b/latest.dump index e69de29bb2d1d6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