{"size": 2207, "ext": "js", "max_stars_repo_path": "server/controllers/Exercises.js", "max_stars_repo_name": "simplesolutionist/FinalProject-master", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/controllers/Exercises.js", "max_issues_repo_name": "simplesolutionist/FinalProject-master", "max_issues_repo_issues_event_min_datetime": "2020-10-25T15:32:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-15T01:15:18.000Z", "max_forks_repo_path": "server/controllers/Exercises.js", "max_forks_repo_name": "simplesolutionist/FinalProject", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 30.2328767123, "max_line_length": 62, "alphanum_fraction": 0.5237879474}
const express = require('express');
const exercises = require('../models/Exercises');
const comments = require('../models/comments');
const reactions = require('../models/reactions');

const router = express.Router();

router
    .get('/', (req, res, next) => {
        exercises.getAll().then(x=> res.send( x ) )
        .catch(next);
    })
    .get('/:id', (req, res, next) => {
        const id = +req.params.id;
        if(!id) return next();
        exercises.get(id).then(x=> res.send( x ) )
        .catch(next);
    })
    .get('/:id/comments', (req, res, next) => {
        const id = +req.params.id;
        if(!id) return next();
        comments.getForExercise(id).then(x=> res.send( x ) )
        .catch(next);
    })
    .get('/:id/reactions', (req, res, next) => {
        const id = +req.params.id;
        if(!id) return next();
        reactions.getForExercise(id).then(x=> res.send( x ) )
        .catch(next);
    })
    .get('/types', (req, res, next) => {
        exercises.getTypes().then(x=> res.send( x ) )
        .catch(next);
    })
    .get('/search', (req, res, next) => {
        exercises.search(req.query.q).then(x=> res.send( x ) )
        .catch(next);
    })
    .post('/', (req, res, next) => {
        exercises.add(exercises.Types.exercisetype,
            req.body.ExerciseDay,
            req.body.ExerciseHeartrate,
            req.body.ExerciseIntensity,
            req.body.ExerciseDuration,
            req.body.ExerciseLocation,
            req.body.Owner_id,).then(newExercise => {
                res.send( newExercise);
            }).catch(next)
    })
   
   .put('/:id', (req, res, next) => {
        exercises.update(exercises.Types.exercisetype,
            req.body.ExerciseDay,
            req.body.ExerciseHeartrate,
            req.body.ExerciseIntensity,
            req.body.ExerciseDuration,
            req.body.ExerciseLocation,
            req.body.Owner_id,).then(newExercise => {
                res.send( newExercise);
            }).catch(next)
    })
    .delete('/:id', (req, res, next) => {
        exercises.remove(req.params.id).then(msg => {
            res.send( msg );
        }).catch(next)
    })
module.exports = router;





