Skip to content

Commit

Permalink
some progress on setting dates correctly...
Browse files Browse the repository at this point in the history
  • Loading branch information
flbarfield committed Oct 16, 2023
1 parent cc0238d commit 8785d32
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
25 changes: 22 additions & 3 deletions controllers/fitnessApp.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
const Exercises = require('../models/exercises')
const moment = require('moment')

module.exports = {
getFitApp: async (req, res) => {
console.log(req.user)
const userName = req.user

try {
const exerciseItems = await Exercises.find({userId: req.user.id})
res.render('fitnessApp.ejs', {exercises: exerciseItems, userName: req.user.userName})

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

}]})

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

res.render('fitnessApp.ejs', {exercises: exerciseItems, userName: req.user.userName, currentDateInput})

} catch (err) {
console.log(err)
}
},

setDate: async (req, res) => {
try {
// TO DO
} catch (err) {
console.log(err)
}
Expand Down
1 change: 1 addition & 0 deletions models/exercises.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mongoose = require('mongoose')
const moment = require('moment')

const ExerciseSchema = new mongoose.Schema({
name: {
Expand Down
8 changes: 8 additions & 0 deletions node_modules/.package-lock.json

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

9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"express-flash": "^0.0.2",
"express-session": "^1.17.3",
"method-override": "^3.0.0",
"moment": "^2.29.4",
"mongodb": "^6.1.0",
"mongoose": "^7.5.3",
"morgan": "^1.10.0",
Expand Down
19 changes: 0 additions & 19 deletions public/assets/js/fitnessApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@ async function quoteApiRequest() {

}

// date setting...for now. This needs to be done via backend so I can populate based off it.
function defaultDate () {
let myDate, day, month, year, date

myDate = new Date
day = myDate.getDate()
if (day < 10){
day = '0' + day
}
month = myDate.getMonth() + 1
if (month < 10){
month = '0' + month
}
year = myDate.getFullYear()
date = `${year}-${month}-${day}`

document.getElementById('date').value = date
}

//show exerciseBank
function showExerciseBank () {
Expand Down Expand Up @@ -151,7 +133,6 @@ const exercises = {
}
}

defaultDate()
populateExerciseBank()
quoteApiRequest()

5 changes: 4 additions & 1 deletion views/fitnessApp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
<section id="content" class="main fitnessBody">
<span class="image main"><img class="fitnessAppImg" src="images/trainingPlaceholderLarge.jpg" alt="" /></span>
<section class="date">
<input id='date' type="date" value=""/>
<form action="/fitnessApp/setDate" method="post">
<input id='date' type="date" value="<%= currentDateInput %>"/>
<button type="submit">Set Date</button>
</form>
</section>
<section class='exerciseList'>
<% exercises.forEach( el => { %>
Expand Down

0 comments on commit 8785d32

Please sign in to comment.