About the project | Functional and non-functional requirements | Routes | Technologies | Preview | Getting started | How to contribute
This is a Node.js HTTP Rest API built with Typescript, Fastify, Prisma, PostgreSQL, JWT and other technologies. It enables a gym system management, including user sign up and authentication, permissions, gym creation and search, and check-in creation, history, metrics, and validation.
The application is fully tested with unit and end-to-end tests using Vitest and Supertest, and adheres to the SOLID principles.
It was developed as a part of Ignite Node.js by Rocketseat 🚀
- It should be possible to register;
- It should be possible to authenticate;
- It should be possible to obtain the profile of a logged-in user;
- It should be possible to obtain the number of check-ins performed by the logged-in user;
- It should be possible for the user to obtain their check-in history;
- It should be possible for the user to search for nearby gyms (up to 10km);
- It should be possible for the user to search for gyms by name;
- It should be possible for the user to check-in at a gym;
- It should be possible to validate a user's check-in;
- It should be possible to register a gym.
- Users should not be able to register with a duplicate email;
- Users cannot make 2 check-ins on the same day;
- Users cannot check-in if they are not near (100m) the gym;
- Check-ins can only be validated up to 20 minutes after being created;
- Check-ins can only be validated by administrators;
- Gyms can only be registered by administrators.
- The user's 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;
- Users should be identified by a JSON Web Token (JWT).
HTTP Method | Route | Description | Request body | Requires authentication token? | Requires admin permission? |
---|---|---|---|---|---|
POST | /users | Creates a new user |
name
password role (ADMIN or MEMBER) |
||
POST | /sessions | Authenticates a user |
email
password |
||
GET | /me | Returns the current logged in user | N/A | ✔️ | |
POST | /gyms | Creates a new gym |
title
description phone latitude longitude |
✔️ | ✔️ |
GET | /gyms/search?q=:searchText&page=:pageNumber | Returns a list of gyms with the given query and page | N/A | ✔️ | |
GET | /gyms/nearby?latitude=:number&longitude=:number | Returns a list of gyms near the given location | N/A | ✔️ | |
POST | /gyms/:gymId/check-ins | Creates a new check-in |
latitude
longitude |
✔️ | |
PATCH | /check-ins/checkInId/validate | Marks the given check-in as validated | N/A | ✔️ | ✔️ |
GET | /check-ins/history | Returns a list of the user's check-ins | N/A | ✔️ | |
GET | /check-ins/metrics | Returns the user's check-ins metrics | N/A | ✔️ |
Technologies used to develop this project:
- Node.js
- Typescript
- Fastify
- Prisma
- PostgreSQL
- JWT (JSON Web Token)
- Zod
- TSup
- Vitest
- Supertest
- Create
.env
file based on.env.example
- Run
npm i
to install the dependencies - Start the Postgresql container with
docker-compose up -d
- Run
npx prisma migrate dev
to run the migrations - Run the development server with
npm run start:dev
- Optionally, import the file
insomnia
on Insomnia to test the routes
- Run
npm run test
- Run
npm run test:e2e
Make a fork of this repository
# Fork using GitHub official command line
# If you don't have the GitHub CLI, use the web site to do that.
$ gh repo fork amanda-santos/gym-api
Follow the steps below
# Clone your fork
$ git clone your-fork-url && cd gym-api
# Create a branch with your feature
$ git checkout -b my-feature
# Make the commit with your changes
$ git commit -m 'feat: My new feature'
# Send the code to your remote branch
$ git push origin my-feature
After your pull request is merged, you can delete your branch
Made with 🧡 by Amanda Santos