Skip to content

Gym management web application that allows you to support clients accounts, gym passes and gym classes live schedule. Track upcoming events, calculate your BMI, check your membership status and prolong your gym pass.

Notifications You must be signed in to change notification settings

RafalG1991/gym-system-manager-be

Repository files navigation

logo

GYM System Manager Project

Gym management web application that allows you to support clients accounts, gym passes and gym classes live schedule. Track upcoming events, calculate your BMI, check your membership status and prolong your gym pass.

This is the backend part of the project with REST API. To see the frontend part visit: https://github.com/RafalG1991/gym-system-manager-fe

To run this project make sure you have created .env file for db credentials: .env structure and configured the mysql database with this structure

💡 Live preview

GYM System Manager live preview

⚙️ Tech stack

frontend

  • React with TypeScript
  • react-testing-library for components tests
  • Cypress for e2e tests

backend

  • Node.js
  • Express.js with TypeScript
  • MySQL database (MariaDB)
  • passport with JWT authentication
  • Jest for unit tests

📝 About development

In this project, for backend, I used Node.js with Express framework. For authentication and authorization support I used passport middleware with JSON Web Token and custom passport strategy.

The project uses TypeScript and frontend-backend shared types. For data storage it uses MySQL database (MariaDB).

User and class records are handled using Active Record pattern. Each class provides basic validation and set of methods to add or modify entities in the database.

Routing is divided into two routes - user and class related. Most of the user routes are available only after authorization using verifyUser middleware.

🎯 API endpoints documentation

USER

POST api/user/signup

Sign up route that checks for unique e-mail, adds new user to the database and returns httpOnly Cookie with user jwt token payload

Accepting JSON:

{
  "email": string,
  "password": string
}

POST api/user/login

Sign in route that verify user data and bcrypt hashed password and returns httpOnly Cookie with user jwt token payload

Accepting JSON:

{
  "email": string,
  "password": string
}

GET api/user/me

Endpoint for checking the authentication status. Returns user payload extracted from cookie, otherwise returns error message which is handled by frontend

GET api/user/data

Returns user data for the frontend

PATCH api/user/

Changing user data route that handles name, bmi and password updating. Can handle three different data sets: firstname and lastname, password or height and weight as in the following example:

Accepting JSON:

{
  "firstname": string,
  "lastname": string
}

OR

{
  "password": string

}

OR

{
  "height": string,
  "weight": string
}

PATCH api/user/membership

Endpoint for extending membership status by the number of months provided in the body

Accepting JSON:

{
  "months": number
}

CLASS

Class routes are intentionally available without any kind of authorization. It can be used in the future for gym classes schedule on the home page

GET api/class

Returns all classes in json format with structure that is handled by react fullcalendar component

GET api/class/:id

Returns single class by id passed in param

🎛 Tests

The project was supplied with Jest tests for class record and user record validation

💾 Available Scripts

In the project directory, you can run:

npm start

Runs the app in ts-node

npm start:dev

Runs the app in development mode

npm test

Launches the test runner

npm run build

Builds the app for production to the build folder.

About

Gym management web application that allows you to support clients accounts, gym passes and gym classes live schedule. Track upcoming events, calculate your BMI, check your membership status and prolong your gym pass.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published