Skip to content

Commit

Permalink
Feature/get-routine-info (#32)
Browse files Browse the repository at this point in the history
* implemented method which returns all routines and their information

* added end point for retreiving all routine info

* corrected sql logic
  • Loading branch information
llam280 authored Aug 21, 2024
1 parent 64a9d6d commit 829d51b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 21 additions & 1 deletion server/controllers/routines-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,30 @@ const deleteRoutine = (req, res) => {

}

const getAllRoutineInfo = (req, res) => {

knex('exercises_history')
.join('exercises', 'exercises_history.name', '=', 'exercises.name')
.join('routines', 'exercises_history.date', '=', 'routines.date')
.select('routines.name as routine_name', 'routines.date', 'exercises_history.set', 'exercises.name as exercise_name', 'exercises_history.weight', 'exercises.muscle_group')
.whereRaw('exercises_history.date = routines.date')
.then(result => {
// Send the query result back as a JSON response
res.json(result);
})
.catch(error => {
// Handle any errors that occurred during the query
console.error('Error fetching routine information:', error);
res.status(500).json({ error: 'An error occurred while fetching routine information' });
});
};


export {
routinesAll,
routineByNameAndDate,
createRoutine,
deleteRoutine,
editRoutine
editRoutine,
getAllRoutineInfo
}
3 changes: 3 additions & 0 deletions server/routes/routines-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ router.delete('/delete/:name/:date', routinesController.deleteRoutine);
//edit a routine
router.put('/edit/:name/:date/:newName/:newDate',routinesController.editRoutine);

//get all routine information
router.get('/all', routinesController.getAllRoutineInfo);


export default router;

0 comments on commit 829d51b

Please sign in to comment.