Skip to content

lukeskw/nodejs-gym-app

Repository files navigation

Gym App

This application allows users to check in at nearby gyms, view their check-in history, and search for gyms by name. Additionally, administrators can validate check-ins and register new gyms.

🚀Technologies

Application Flow

In this flow, we present the steps for authentication, check-in, check-in validation, gym search, and obtaining metrics.

gym-app-flow

Running the application

Setting up the environment

Setting up the environment

Make sure you have Node.js, Docker, and Docker Compose installed on your system.

  1. Cloning the repository

    git clone https://github.com/your-username/gym-app.git
    cd gym-app
  2. Installing dependencies

    npm install
  3. Configuring environment variables

    Copy the .env.example to a .env file in the root of the project

  4. Running with Docker Compose

    Use the provided Docker Compose file to set up the PostgreSQL database:

    Then run:

    docker-compose up -d
  5. Running database migrations

    npx prisma migrate dev
  6. Running the application

    npm run dev

    Access http://localhost:3000 in your browser.

Endpoints

Endpoints

Users

  • POST /users: Create a new user

    {
      "name": "John Doe",
      "email": "johndoe@gmail.com",
      "password": "1a2b3c"
    }
  • POST /sessions: Create a session (login) for the user

    {
      "email": "johndoe@gmail.com",
      "password": "1a2b3c"
    }
  • POST /sessions/refresh: Refresh access token

    {
      "email": "johndoe@gmail.com",
      "password": "1a2b3c"
    }
  • GET /me: Get the profile of the logged-in user

Check-Ins

  • GET /check-ins/history: Get the user's check-in history

  • GET /check-ins/metrics: Get total check-in metrics for the user

  • POST /gyms/:gymId/check-ins: Check in at a gym

    {
      "gymId": "1234567890"
    }
  • PATCH /check-ins/:checkInId/validate: Validate a check-in (Admins only)

    {
      "checkInId": "0987654321"
    }

Gyms

  • GET /gyms/search: Search gyms by name

    • Query Params:
      • name: Name of the gym to search for
  • GET /gyms/nearby: Get nearby gyms (within 10km)

    • Query Params:
      • latitude: User's latitude
      • longitude: User's longitude
  • POST /gyms: Register a new gym (Admins only)

    {
      "name": "Test Gym",
      "latitude": "-23.5505",
      "longitude": "-46.6333"
    }

Tests

The application is covered by unit and E2E tests

Requirements

Functional Requirements

  • Should be possible to register;
  • Should be possible to authenticate;
  • Should be possible to get logged user profile information;
  • Should be possible to obtain the total check-in quantity of the logged user;
  • Should be possible to the user to get his check-in history;
  • Should be possible to get the closest gyms (in a 10km range);
  • Should be possible to search for gyms by their name;
  • Should be possible to the user to do a check-in operation in a gym;
  • Should be possible to validate user check-in;
  • Should be possible to register a gym;

Business Rules

  • User cant register with a duplicate email address;
  • User cant do 2 check-ins in the same day;
  • User cant do a check-in operation if he's close (100mts) to the gym;
  • Check-in can only be validated until after 20 minutes after creation;
  • Check-in can only be validated by admins;
  • Gym can only be registered by admins;

Non-Functional Requirements

  • User's password must be cryptographed;
  • Application data must be persisted on a PostgreSQL database;
  • All data lists must be paginated with 20 items per page;
  • User must be identified by a JWT token (JSON Web Token);

Notes

User passwords are encrypted before being stored in the database.

All application data is persisted in a PostgreSQL database.

All data lists are paginated, displaying 20 items per page.

The user is identified by a JWT (JSON Web Token) during the session.