Skip to content

Commit

Permalink
fixing affirmation routes
Browse files Browse the repository at this point in the history
  • Loading branch information
abutler911 committed Oct 22, 2023
1 parent f737c26 commit 22c58ec
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
1 change: 1 addition & 0 deletions public/css/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.form-heading {
font-size: 2em;
margin-bottom: 0.5em;
text-align: center;
}

.form-subheading {
Expand Down
1 change: 0 additions & 1 deletion public/css/main-container.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ hr {
justify-content: center;
min-height: 100vh;
margin: auto;
background-color: #f7f7f7;
}
22 changes: 14 additions & 8 deletions routes/affirmationRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,35 @@ router.get("/affirmation-setup", async (req, res) => {
user = await User.findById(userId);
}

res.render("affirmation-setup", { user });
res.render("affirmation-setup", { user: user.toObject() });
});

router.get("/enter-affirmations", (req, res) => {
res.render("enter-affirmations");
});

router.post("/submit-affirmations", async (req, res) => {
const userId = req.session.passport.user; // Make sure the user is authenticated
const userId = req.session.passport.user;
console.log("Request body:", req.body);

try {
const user = await User.findById(userId);
console.log("User before update:", JSON.stringify(user, null, 2));

if (user) {
user.affirmations = {
addressingInsecurities: req.body.addressingInsecurities,
shiftingToDesires: req.body.shiftingToDesires,
givingPermission: req.body.givingPermission,
affirmationsAndGratitude: req.body.affirmationsAndGratitude,
addressingInsecurities: req.body.addressinginsecurities,
shiftingToDesires: req.body.shiftingtodesires,
givingPermission: req.body.givingpermission,
affirmationsAndGratitude: req.body.affirmationsandgratitude,
};

await user.save();
res.redirect("/affirmations"); // Redirect to a page to display affirmations
console.log("User after update:", JSON.stringify(user, null, 2));

const result = await user.save();
console.log("Save result:", result);

res.redirect("/affirmation-setup");
}
} catch (err) {
console.log("Error:", err);
Expand Down
20 changes: 14 additions & 6 deletions views/affirmation-setup.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ block content
h1 Hello, #{user.username}
h2.form-heading Affirmation Setup

// Input for setting affirmation duration
form(action="/set-affirmation-duration" method="POST")
label(for="affirmationDuration") Set Duration (in seconds):
input(type="number" id="affirmationDuration" name="affirmationDuration" value=user.affirmationDuration || "")
input(type="submit" value="Set Duration")

// Check if affirmations exist
if user.affirmations && user.affirmations.length > 0
ul.affirmation-list
each affirmation in user.affirmations
li= affirmation
if user.affirmations
each category, categoryName in user.affirmations
h3= categoryName
ul.affirmation-list
each affirmation, point in category
li #{point}: #{affirmation}
// Button to enter new affirmations
a.btn.btn-primary(href="/enter-affirmations") Enter New Affirmations
else
p.prompt You have no affirmations. Would you like to #[a(href="/enter-affirmations") enter some]?


41 changes: 13 additions & 28 deletions views/enter-affirmations.pug
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
extends layout

block content
div.main-container
div.center-container
div.main-container.container
div.center-container.text-center
h1 Enter Your Affirmations
form(action="/submit-affirmations" method="POST" class="affirmation-form")
form(action="/submit-affirmations" method="POST", class="affirmation-form")

div.affirmation-section
h3 Addressing Insecurities
each point in ['topOfHead', 'eyebrow', 'sideOfEye', 'underEye', 'underNose', 'chin', 'collarbone', 'underArm']
label(for=`addressingInsecurities[${point}]`) #{point}
textarea(name=`addressingInsecurities[${point}]`, rows="2", cols="50")

div.affirmation-section
h3 Shifting to Desires
each point in ['topOfHead', 'eyebrow', 'sideOfEye', 'underEye', 'underNose', 'chin', 'collarbone', 'underArm']
label(for=`shiftingToDesires[${point}]`) #{point}
textarea(name=`shiftingToDesires[${point}]`, rows="2", cols="50")

div.affirmation-section
h3 Giving Permission
each point in ['topOfHead', 'eyebrow', 'sideOfEye', 'underEye', 'underNose', 'chin', 'collarbone', 'underArm']
label(for=`givingPermission[${point}]`) #{point}
textarea(name=`givingPermission[${point}]`, rows="2", cols="50")

div.affirmation-section
h3 Affirmations and Gratitude
each point in ['topOfHead', 'eyebrow', 'sideOfEye', 'underEye', 'underNose', 'chin', 'collarbone', 'underArm']
label(for=`affirmationsAndGratitude[${point}]`) #{point}
textarea(name=`affirmationsAndGratitude[${point}]`, rows="2", cols="50")

input(type="submit" value="Submit" class="submit-button")
each section in ['Addressing Insecurities', 'Shifting to Desires', 'Giving Permission', 'Affirmations and Gratitude']
div.affirmation-section
h3 #{section}
div.row
each point in ['topOfHead', 'eyebrow', 'sideOfEye', 'underEye', 'underNose', 'chin', 'collarbone', 'underArm']
div.col-md-6.form-group
label(for=`${section.toLowerCase().replace(/\s+/g, '')}[${point}]`) #{point}
textarea.form-control(name=`${section.toLowerCase().replace(/\s+/g, '')}[${point}]`, rows="2")

button.btn.btn-primary(type="submit") Submit
4 changes: 2 additions & 2 deletions views/login.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ extends layout
block content
div(class="center-container")
// Flash Messages
if success_msg
if success_msg && success_msg.length > 0
div(class="flash-success")
= success_msg

if error_msg
if error_msg && error_msg.length > 0
div(class="flash-error")
= error_msg

Expand Down

0 comments on commit 22c58ec

Please sign in to comment.