Skip to content

Instantly share code, notes, and snippets.

@beaucarnes
Created April 29, 2019 20:16
Show Gist options
  • Save beaucarnes/2a88227278bd6764a2d00e0c6f7a9a28 to your computer and use it in GitHub Desktop.
Save beaucarnes/2a88227278bd6764a2d00e0c6f7a9a28 to your computer and use it in GitHub Desktop.
const router = require('express').Router();
let Exercise = require('../models/exercise.model');
router.route('/').get((req, res) => {
Exercise.find()
.then(exercises => res.json(exercises))
.catch(err => res.status(400).json('Error: ' + err));
});
router.route('/add').post((req, res) => {
const username = req.body.username;
const description = req.body.description;
const duration = Number(req.body.duration);
const date = Date.parse(req.body.date);
const newExercise = new Exercise({
username,
description,
duration,
date,
});
newExercise.save()
.then(() => res.json('Exercise added!'))
.catch(err => res.status(400).json('Error: ' + err));
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment