/fitness-tracker

Track your most recent workouts

Primary LanguageJavaScriptMIT LicenseMIT

Fitness Tracker

Languages Top Language Code Size Repo Size Total Lines Express V Mongoose V Morgan V Last Commit Followers

Description

Track your workouts with Fitness Tracker. The app will keep track of every exercise in your workout. The app dashboard will display weekly summary graphs of all workouts done in a week.

Table of Contents

Installation

  1. Clone repository.
  2. Check in routes/api-routes and comment in block of code if you want the database to be prepopulated with dummy values
  3. npm install
  4. node server.js

Running seeders/seed.js is optional to have a prepopulated database.

Usage

Screeshots

  1. Homepage displaying last workout

Site

  1. Creating Workouts

Site

  1. Last Week's Summary

Site

Snippets

  1. Adding to an array type
    // add exercise
    app.put("/api/workouts/:id", (req, res) => {

        db.Workout.findOneAndUpdate(
            { _id: req.params.id },
            {
                $inc: { totalDuration: req.body.duration },
                $push: { exercises: req.body }
            },
            { new: true }).then(dbWorkout => {
                res.json(dbWorkout);
            }).catch(err => {
                res.json(err);
            });

    });
    
  • This function will add an exercise to the array of exercises that belong to the workout with the given id. Here we will locate the workout with the given ID and update its fields. We will increase the total duration of the workout by the duration of the exercise being inserted. We will push the exercise to the array of exercises.

Credits

Author

Built With

License

License