Allow users to register themselves as admin or members, allow admin users to create gyms and validate check-ins. Allow members to check-in, get their profile, search/fetch gyms. and much more! The app has pagination and use JWT to authentication.
Easy peasy lemon squeezy:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
andprettier
to keep the code clean and patterned.
The application uses just one database: Postgres.
Responsible to store all application data. If for any reason you would like to create a Postgres container instead of use docker-compose
, you can do it by running the following command:
$ docker run --name ignite-gym-postgres -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres
Remember to run the database migrations:
$ npx prisma migrate dev
See more information on Prisma Migrate.
In this file you may configure your JWT settings, the environment, app's port and database connection Url. Rename the .env.example
in the root directory to .env
then just update with your settings.
key | description | default |
---|---|---|
PORT | Port number where the app will run. | 3333 |
NODE_ENV | App environment. | dev |
JWT_SECRET | A alphanumeric random string. Used to create signed tokens. | - |
DATABASE_URL | Database connection Url. | postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public |
To start up the app run:
$ yarn dev:server
Or:
npm run dev:server
A few routes expect a Bearer Token in an Authorization
header.
You can see these routes in the routes section.
POST http://localhost:3333/gyms Authorization: Bearer <token>
Get your token after authenticate through the
/sessions
route, it returns atoken
key with a Bearer Token.
route | HTTP Method | params | description | auth method |
---|---|---|---|---|
/users |
POST | Body with user name , email and password . |
Create new user. | ❌ |
/sessions |
POST | Body with user email and password . |
Authenticates user and return a Bearer Token. | ❌ |
/token/refresh |
PATCH | Cookie with the refreshToken generate in the # (/sessions ). |
Generate a new Bearer Token. | ❌ |
/me |
GET | - | Get the logged in user profile. | Bearer |
/gyms |
POST | Body with gym name , description , phone , latitude and longitude . |
Create a new gym. Only ADMIN users are allowed. |
Bearer |
/gyms/nearby |
GET | Query parameters with user current latitude and longitude . |
Look for gyms nearby of the user. | Bearer |
/gyms/search |
GET | Query parameters with q (query to use in the search) and optionally page . |
Search for gyms based in the query provided. | Bearer |
/gyms/:gymId/check-ins |
POST | Body with user current latitude and longitude . |
Check in user on a gym. | Bearer |
/check-ins/:checkInId/validate |
PATCH | - | Validate an user check-in. Only ADMIN users are allowed. |
Bearer |
/check-ins/history |
GET | - | Return user's check-ins. | Bearer |
/check-ins/metrics |
GET | - | Return user's check-ins count. | Bearer |
Routes with
Bearer
as auth method expect anAuthorization
header. See Bearer Token section for more information.
POST /users
Request body:
{
"name": "John Doe",
"email": "johndoe@example.com",
"password": "123456"
}
POST /sessions
Request body:
{
"email": "johndoe@example.com",
"password": "123456"
}
POST /gyms
Request body:
{
"name": "Ignite Gym",
"description": "Gym for Ignite Students",
"phone": "8772810274",
"latitude": "79.1721",
"longitude": "43.0377"
}
POST /gyms/:gymId/check-ins
Request body:
{
"latitude": "79.1721",
"longitude": "43.0377"
}
Vitest was the choice to test the app, to run the unit tests:
$ yarn test:unit
Or:
$ npm run test:unit
And to run the E2E tests:
$ yarn test:e2e
Or:
$ npm run test:e2e
You can see the coverage report inside tests/coverage
. They are automatically created after the tests run.