Visão geral do projeto, um pouco das tecnologias usadas.
Diagrama ER da API definindo bem as relações entre as tabelas do banco de dados.
Clone o projeto em sua máquina e instale as dependências com o comando:
yarn
Em seguida, crie um arquivo .env, copiando o formato do arquivo .env.example:
cp .env.example .env
Configure suas variáveis de ambiente com suas credenciais do Postgres e uma nova database da sua escolha.
Execute as migrations com o comando:
yarn typeorm migration:run -d src/data-source.ts
A criação do usuário é definida pelos campos abaixo, a diferença de um cliente para um personal é o campo adm.
Campo | Tipo | Descrição |
---|---|---|
id | string | Identificador único do usuário. |
name | string | O nome do usuário. |
string | O e-mail do usuário. | |
age | string | A idade do usuário. |
password | string | A senha de acesso do usuário. |
phone_number | string | O número de contato do usuário. |
status | boolean | A condição para o usuário ativo ou inativo. |
adm | boolean | Define se um usuário é um Client ou um Personal. |
plan | string | O tipo de plano de academia. |
checkin | string | Horário de entrada na academia |
checkout | string | Horário de saída da academia |
lock_number | string | É o número de armário da academia |
Método | Rota | Descrição |
---|---|---|
POST | /register | Criação de um cliente ou personal. |
POST | /login | Gera o token de autenticação. |
GET | /users | Lista todos os usuários. |
GET | /clients/:id | Lista um cliente usando seu ID como parâmetro |
POST /register
Host: http://localhost:3000
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZlNTlkMmQ2LTg5MmUtNGE5OC1iNjJjLWJiM2RkZWVmYWM4MiIsImFkbSI6ZmFsc2UsImlhdCI6MTY1ODM1MTk2MiwiZXhwIjoxNjU4MzU1NTYyfQ._S5WW_T4kDMnVTLjESv2GqQgjO21pNBW9O2dxejWXFM
Content-type: application/json
{
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "1234",
"phone_number": "9819839189",
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"street": "Rua 007",
"cep": "59695-000",
"number": "25",
"town": "Floripa",
"state": "SC"
}
201 Created
{
"id": "78592cd4-86f9-4a0d-80f6-616a0b8ef6f1",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"status": true,
"street": "Rua 007",
"number": "25",
"town": "Floripa",
"state": "SC"
}
Código do Erro | Descrição |
---|---|
409 Conflict | Email already registered. |
POST /login
Host: http://localhost:3000
Authorization: None
Content-type: application/json
{
"email": "[email protected]",
"password": "1234"
}
201 Created
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZlNTlkMmQ2LTg5MmUtNGE5OC1iNjJjLWJiM2RkZWVmYWM4MiIsImFkbSI6ZmFsc2UsImlhdCI6MTY1ODM1NDM4MiwiZXhwIjoxNjU4MzU3OTgyfQ.ERXtzLfQ9KtDsMaqWrQczgonuYxGo9XT5a6bI0u2ZkU"
}
Código do Erro | Descrição |
---|---|
403 Forbidden | Wrong email/password. |
404 Not Found | Account not found. |
GET /users
Host: http://localhost:3000
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZlNTlkMmQ2LTg5MmUtNGE5OC1iNjJjLWJiM2RkZWVmYWM4MiIsImFkbSI6ZmFsc2UsImlhdCI6MTY1ODM1MTk2MiwiZXhwIjoxNjU4MzU1NTYyfQ._S5WW_T4kDMnVTLjESv2GqQgjO21pNBW9O2dxejWXFM
Content-type: application/json
Para listar todos os usuários, você deve estar logado e com permissão de administrador.
Vazio
200 OK
[
{
"id": "36489681-bd4b-47c5-ad11-eaaef2e80b6d",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "$2a$10$9PPZtwZf4kNoWaHVKuf0N.2QgU2HFfvtDDulrHsCGeuBUuK6T8KOi",
"phone_number": "9819839189",
"status": true,
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"created_at": "2022-07-20T20:25:01.059Z",
"updated_at": "2022-07-20T20:25:01.059Z",
"avaliations": [],
"journals": [],
"addresses": [
{
"id": "92905f3b-5d5d-4400-a615-fbe0677f3cc6",
"street": "Rua 007",
"number": "25",
"cep": "59695-000",
"complement": null,
"town": "Floripa",
"state": "SC"
}
]
}
]
Código do Erro | Descrição |
---|---|
401 Unathorized | Invalid token. |
403 Forbidden | Needs admin permission to access. |
GET /users/36489681-bd4b-47c5-ad11-eaaef2e80b6d
Host: http://localhost:3000
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZlNTlkMmQ2LTg5MmUtNGE5OC1iNjJjLWJiM2RkZWVmYWM4MiIsImFkbSI6ZmFsc2UsImlhdCI6MTY1ODM1MTk2MiwiZXhwIjoxNjU4MzU1NTYyfQ._S5WW_T4kDMnVTLjESv2GqQgjO21pNBW9O2dxejWXFM
Content-type: application/json
200 OK
[
{
"id": "36489681-bd4b-47c5-ad11-eaaef2e80b6d",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "$2a$10$9PPZtwZf4kNoWaHVKuf0N.2QgU2HFfvtDDulrHsCGeuBUuK6T8KOi",
"phone_number": "9819839189",
"status": true,
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"created_at": "2022-07-20T20:25:01.059Z",
"updated_at": "2022-07-20T20:25:01.059Z",
"addresses": [
{
"id": "92905f3b-5d5d-4400-a615-fbe0677f3cc6",
"street": "Rua 007",
"number": "25",
"cep": "59695-000",
"complement": null,
"town": "Floripa",
"state": "SC"
}
]
}
]
Código do Erro | Descrição |
---|---|
401 Unathorized | Invalid token. |
403 Forbidden | Needs admin permission to access. |
POST /avaliations/36489681-bd4b-47c5-ad11-eaaef2e80b6d
Host: http://localhost:3000
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZlNTlkMmQ2LTg5MmUtNGE5OC1iNjJjLWJiM2RkZWVmYWM4MiIsImFkbSI6ZmFsc2UsImlhdCI6MTY1ODM1MTk2MiwiZXhwIjoxNjU4MzU1NTYyfQ._S5WW_T4kDMnVTLjESv2GqQgjO21pNBW9O2dxejWXFM
Content-type: application/json
{
"wheight": 80,
"height": 180,
"neck": "35.6",
"waist": 693,
"bust": 36,
"hip": 833,
"arm_right": 333,
"arm_left": 332,
"leg_left": 500,
"leg_right": 504,
"cardio_freq": 80,
"circumference": 90,
"diameter": 45
}
201 CREATED
[
{
"message": "Avaliation created",
"avaliation": {
"wheight": 80,
"height": 180,
"neck": "35.6",
"waist": 693,
"bust": 36,
"hip": 833,
"arm_right": 333,
"arm_left": 332,
"leg_right": 504,
"leg_left": 500,
"cardio_freq": 80,
"circumference": 90,
"diameter": 45,
"created_at": "2022-07-21T00:00:37.306Z",
"updated_at": "2022-07-21T00:00:37.306Z",
"data_client_personal": [
{
"id": "36489681-bd4b-47c5-ad11-eaaef2e80b6d",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "$2a$10$9PPZtwZf4kNoWaHVKuf0N.2QgU2HFfvtDDulrHsCGeuBUuK6T8KOi",
"phone_number": "9819839189",
"status": true,
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"created_at": "2022-07-20T20:25:01.059Z",
"updated_at": "2022-07-20T20:25:01.059Z",
"addresses": [
{
"id": "92905f3b-5d5d-4400-a615-fbe0677f3cc6",
"street": "Rua 007",
"number": "25",
"cep": "59695-000",
"complement": null,
"town": "Floripa",
"state": "SC"
}
]
}
],
"id": "11288fd9-5c1c-40b8-a6c9-66b95574f0fb"
}
}
]
GET /avaliations/list
Host: http://localhost:3000
Authorization:
Content-type: application/json
Vazio
200 OK
[
{
"id": "11288fd9-5c1c-40b8-a6c9-66b95574f0fb",
"wheight": 80,
"height": 180,
"neck": "35.6",
"waist": 693,
"bust": 36,
"hip": 833,
"arm_right": 333,
"arm_left": 332,
"leg_right": 504,
"leg_left": 500,
"cardio_freq": 80,
"circumference": 90,
"diameter": 45,
"created_at": "2022-07-21T00:00:37.306Z",
"updated_at": "2022-07-21T00:00:37.306Z",
"data_client_personal": [
{
"id": "36489681-bd4b-47c5-ad11-eaaef2e80b6d",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "$2a$10$9PPZtwZf4kNoWaHVKuf0N.2QgU2HFfvtDDulrHsCGeuBUuK6T8KOi",
"phone_number": "9819839189",
"status": true,
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"created_at": "2022-07-20T20:25:01.059Z",
"updated_at": "2022-07-20T20:25:01.059Z",
"addresses": [
{
"id": "92905f3b-5d5d-4400-a615-fbe0677f3cc6",
"street": "Rua 007",
"number": "25",
"cep": "59695-000",
"complement": null,
"town": "Floripa",
"state": "SC"
}
]
}
]
},
GET /avaliations/list/{{ _['base-Url'] }}/avaliations/list/36489681-bd4b-47c5-ad11-eaaef2e80b6d
Host: http://localhost:3000
Authorization:
Content-type: application/json
Vazio
200 OK
[
{
"id": "11288fd9-5c1c-40b8-a6c9-66b95574f0fb",
"wheight": 80,
"height": 180,
"neck": "35.6",
"waist": 693,
"bust": 36,
"hip": 833,
"arm_right": 333,
"arm_left": 332,
"leg_right": 504,
"leg_left": 500,
"cardio_freq": 80,
"circumference": 90,
"diameter": 45,
"created_at": "2022-07-21T00:00:37.306Z",
"updated_at": "2022-07-21T00:00:37.306Z",
"data_client_personal": [
{
"id": "36489681-bd4b-47c5-ad11-eaaef2e80b6d",
"name": "Alex",
"email": "[email protected]",
"age": "28",
"password": "$2a$10$9PPZtwZf4kNoWaHVKuf0N.2QgU2HFfvtDDulrHsCGeuBUuK6T8KOi",
"phone_number": "9819839189",
"status": true,
"adm": true,
"plan": "Family",
"checkin": "3 horas",
"checkout": "2 horas",
"lock_number": 2,
"created_at": "2022-07-20T20:25:01.059Z",
"updated_at": "2022-07-20T20:25:01.059Z",
"addresses": [
{
"id": "92905f3b-5d5d-4400-a615-fbe0677f3cc6",
"street": "Rua 007",
"number": "25",
"cep": "59695-000",
"complement": null,
"town": "Floripa",
"state": "SC"
}
]
}
]
}
]
GET /avaliations/11288fd9-5c1c-40b8-a6c9-66b95574f0fb
Host: http://localhost:3000
Authorization:
Content-type: application/json
{
"height": 200
}
200 OK
{
"message": "Avaliation Updated",
"updated_avaliation": {
"id": "11288fd9-5c1c-40b8-a6c9-66b95574f0fb",
"wheight": 80,
"height": 200,
"neck": "35.6",
"waist": 693,
"bust": 36,
"hip": 833,
"arm_right": 333,
"arm_left": 332,
"leg_right": 504,
"leg_left": 500,
"cardio_freq": 80,
"circumference": 90,
"diameter": 45,
"created_at": "2022-07-21T00:00:37.306Z",
"updated_at": "2022-07-21T01:07:47.000Z"
}
}