Skip to content

Commit

Permalink
Can pull up right exercises for right dates! But no styling! SO CLOSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
flbarfield committed Oct 16, 2023
1 parent 4b0b1e7 commit 5c7da7c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
17 changes: 15 additions & 2 deletions controllers/fitnessApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ module.exports = {
}
},

setDate: async (req, res) => {
getUserDateEntries: async (req, res) => {
try {
// TO DO
const reqDate = moment(req.body.userDate)
const startOfUserDate = reqDate.startOf('day').toString()
const endOfUserDate = reqDate.endOf('day').toString()

const exerciseItems = await Exercises.find({$and: [
{userId: req.user.id},
{date: {'$gte': startOfUserDate,
'$lt': endOfUserDate}

}]})

let currentDateInput = moment(reqDate).format('YYYY-MM-DD')

res.render('fitnessApp.ejs', {exercises: exerciseItems, userName: req.user.userName, currentDateInput})
} catch (err) {
console.log(err)
}
Expand Down
14 changes: 0 additions & 14 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions routes/fitnessApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {ensureAuth} = require('../middleware/auth')

router.get('/', ensureAuth, fitnessAppController.getFitApp)

router.get('/getUserDateEntries', fitnessAppController.getUserDateEntries)

router.post('/createExercise', fitnessAppController.createExercise)

router.put('/modRep:id', fitnessAppController.modRep)
Expand Down
4 changes: 2 additions & 2 deletions views/fitnessApp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<section id="content" class="main fitnessBody">
<span class="image main"><img class="fitnessAppImg" src="images/trainingPlaceholderLarge.jpg" alt="" /></span>
<section class="date">
<form action="/fitnessApp/setDate" method="post">
<input id='date' type="date" value="<%= currentDateInput %>"/>
<form action="/fitnessApp/getUserDateEntries?_method=GET" method="post">
<input id='date' name="userDate" type="date" value="<%= currentDateInput %>"/>
<button type="submit">Set Date</button>
</form>
</section>
Expand Down

0 comments on commit 5c7da7c

Please sign in to comment.