Created
April 29, 2019 20:16
-
-
Save beaucarnes/2a88227278bd6764a2d00e0c6f7a9a28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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