mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 06:32:11 +00:00
added methods and routes for getting an exercises history, and the sum of a workouts musclearrays -- incl a modifier
This commit is contained in:
@@ -30,4 +30,43 @@ module.exports = function(app) {
|
||||
|
||||
});
|
||||
|
||||
app.get('/api/getexercisemodifier/:userid/:exerciseid', function(req, res) {
|
||||
res.contentType('json');
|
||||
console.log('userID' + req.params.userid);
|
||||
console.log('exerciseID' + req.params.exerciseid);
|
||||
//DB search workouts
|
||||
// where userid
|
||||
//where exerciseid
|
||||
|
||||
Workout
|
||||
.where('userID', req.params.userid)
|
||||
.where('elements.exerciseID', req.params.exerciseid)
|
||||
.select('elements')
|
||||
// .exec(callback);
|
||||
|
||||
// workout.findOne({_id: req.params._id})
|
||||
// //.populate('elements.exerciseID')
|
||||
.exec(function(err, workout) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (! workout) {
|
||||
return res.send('Not found', 404);
|
||||
}
|
||||
//need for loop for workout as it returns an array
|
||||
var filteredarray = workout[0].elements.filter( function(i) {
|
||||
return i.exerciseID == req.params.exerciseid;
|
||||
});
|
||||
// then for each in filtered array grab sets reps weight
|
||||
// punch that into an array.
|
||||
|
||||
// res.send(filteredarray);
|
||||
// //console.log("hmm" + JSON.stringify(workout[0].elements));
|
||||
res.send(workout);
|
||||
//next();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
@@ -3,7 +3,7 @@ var workout = require('../../data/models/workout');
|
||||
function loadworkout(req, res, next) {
|
||||
console.log('fetch id' + req.params._id );
|
||||
workout.findOne({_id: req.params._id})
|
||||
//.populate('elements')
|
||||
.populate('elements.exerciseID')
|
||||
.exec(function(err, workout) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@@ -11,6 +11,7 @@ var loggedIn = require('./middleware/logged_in');
|
||||
var maxWorkoutsPerPage = 5;
|
||||
var Exercise = require('../data/models/exercise');
|
||||
var loadExercise = require('./middleware/load_exercise');
|
||||
var MuscleArray = require('./middleware/musclearray');
|
||||
var Moment = require('moment');
|
||||
|
||||
module.exports = function(app) {
|
||||
@@ -60,8 +61,11 @@ module.exports = function(app) {
|
||||
});
|
||||
|
||||
|
||||
app.get('/workouts/:_id', loadWorkout, function(req, res, next){
|
||||
app.get('/workouts/:_id', loggedIn, loadWorkout, function(req, res, next){
|
||||
console.log("time" + Moment.utc(req.workout.workoutDate).format("ddd, hA"));
|
||||
var output = MuscleArray(req.workout);
|
||||
console.log('output - ' + JSON.stringify(output));
|
||||
|
||||
res.render('workouts/workout', {title: req.workout.title,
|
||||
workout: req.workout,
|
||||
workouttime: Moment.utc(req.workout.workoutDate).format("ddd, hA")
|
||||
|
||||
Reference in New Issue
Block a user