/gympass-node-api

A NodeJS API to manage users gym membership across multiple gyms.

Primary LanguageTypeScript

Gympass Node API

Environment dependencies

Node.js PostgreSQL Docker pnpm

Dependencies

Fastify Prisma Vitest supertest bcryptjs dayjs Zod eslint dotenv

gympass-node-api is a Node.js API designed to manage users' gym memberships across multiple gyms. It is built entirely in TypeScript and utilizes SOLID principles on its implementation.

Getting Started

  1. Clone this repo:
$ git clone https://github.com/DaniloNR/gympass-node-api.git
  1. Then go to the project's folder:
cd gympass-node-api
  1. Before running anything, make sure you are using node v20
nvm use 20
  1. Install all dependencies:
pnpm install
  1. Start the docker container for the database:
docker compose up -d

Note: -d refers to "detach" so the process will keep running even if the terminal is closed. If you want to stop the container just run:

docker compose stop
  1. Run migrations:
pnpm migrate
  1. Generate prisma types:
pnpm generate:types
  1. Run locally:
pnpm start:dev

Workflows

There are two workflows configured on this repository for running tests

  • E2E Testing: .github/workflows/e2e-testing.yml triggers on any pull_request
  • Unit Testing: .github/workflows/unit-testing.yml triggers on any push

Dependabot

There is a additional workflow configured on this repository, the dependabot. A .npmrc is setup containing a rule to prevent any package from being updated when running a > pnpm install, instead, the updates are performed by dependabot on GitHub through pull requests weekly. If the tests pipelines pass, you can merge to update the dependencies. Also, whenever package.json updates, the badges on README are updated as well through a workflow called update-badges.yml.

SOLID Principles

The project is built using the SOLID principles, which are:

  • Single Responsibility Principle
  • Open/Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

Testing

All you need to test the application is to run the scrips on package.json Unit tests:

pnpm test

E2E tests:

pnpm test:e2e

if you want to run on watch mode, just add :watch on the script and run.

Vitest-environments

Vitest-environments is utilized for handling end-to-end tests by creating a new schema on PostgreSQL before the test runs and destroying it after. The environment configuration can be found on vitest-environments/prisma.ts

Functional Requirements

  • User registration must be possible;
  • User authentication must be possible;
  • It must be possible to retrieve the profile of a logged-in user;
  • It must be possible to retrieve the number of check-ins performed by the logged-in user;
  • It must be possible for the user to retrieve their check-in history;
  • It must be possible for the user to search for nearby gyms up to 10km;
  • It must be possible for the user to search for gyms by name;
  • It must be possible for the user to check-in at a gym;
  • User check-in must be validated;
  • It must be possible to register a gym;

Business Rules

  • The user must not be able to register with a duplicate email;
  • The user cannot make 2 check-ins on the same day;
  • The user cannot check-in if not near (100m) the gym;
  • Check-in can only be validated up to 20 minutes after it is created;
  • Check-in can only be validated by administrators;
  • The gym can only be registered by administrators;

Non-functional Requirements

  • User password needs to be encrypted;
  • Application data needs to be persisted in a PostgreSQL database;
  • All data lists need to be paginated with 20 items per page;
  • User must be identified by a JWT (JSON Web Token);

License

MIT License © Danilo Nogueira

Open Source

Feel free to clone this repo and use the way you want it!