@@ -18,12 +18,15 @@ const {
1818workoutRouter . post ( '/' , ( request , response ) => {
1919
2020 const newWorkout = {
21- // user: request.user.id ,
21+ user : request . body . user ,
2222 exercise : request . body . exercise ,
2323 reps : request . body . reps ,
2424 weight : request . body . weight ,
25- set : request . body . set
25+ set : request . body . set ,
26+ date : request . body . date
27+
2628 } ;
29+ console . log ( newWorkout )
2730
2831 const validation = Joi . validate ( newWorkout , WorkoutJoiSchema ) ;
2932 if ( validation . error ) {
@@ -35,17 +38,31 @@ workoutRouter.post('/', (request, response) => {
3538
3639 Workout . create ( newWorkout )
3740 . then ( createdWorkout => {
41+ console . log ( "Workout Created" )
3842 return response . status ( HTTP_STATUS_CODES . CREATED ) . json ( createdWorkout . serialize ( ) ) ;
3943 } )
4044 . catch ( error => {
41- return response . status ( HTTP_STATUS_CODES . INTERNAL_SERVER_ERROR ) . json ( error ) ;
45+ console . log ( error )
46+ return response . status ( HTTP_STATUS_CODES . INTERNAL_SERVER_ERROR ) . send ( error ) ;
4247 } )
4348 } )
4449 // jwtPassportMiddleware,
45- workoutRouter . get ( '/' , jwtPassportMiddleware , ( request , response ) => {
50+ workoutRouter . get ( '/' , ( request , response ) => {
4651 console . log ( "Your Workouts" )
47- response . sendFile ( path . resolve ( './app/views/auth/home.html' ) ) ;
48- // response.send('Text here')
52+ Workout . find ( )
53+ . then ( workouts => {
54+ // Step 2A: Return the correct HTTP status code, and the users correctly formatted via serialization.
55+
56+ return response . status ( HTTP_STATUS_CODES . OK ) . json (
57+ workouts . map ( workout => workout . serialize ( ) )
58+ ) ;
59+
60+
61+ } )
62+ . catch ( error => {
63+ // Step 2B: If an error ocurred, return an error HTTP status code and the error in JSON format.
64+ return response . status ( HTTP_STATUS_CODES . INTERNAL_SERVER_ERROR ) . json ( error ) ;
65+ } ) ;
4966} )
5067
5168module . exports = {
0 commit comments