-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3230aa6
Showing
24 changed files
with
10,232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = crlf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": ["standard-with-typescript", "prettier"], | ||
"overrides": [], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
dist | ||
*.log | ||
*.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
*.log | ||
*.sqlite3 | ||
./thunder-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 4, | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cSpell.words": ["datetime", "knexfile", "ngneat", "tsup"], | ||
"thunder-client.saveToWorkspace": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# O Desafio | ||
|
||
No contexto dos meios de pagamento, o desafio é construir uma API Restful para gestão de contas. | ||
|
||
Mais detalhes no repositório [cdt-baas/desafio-dev-api-rest](https://github.com/cdt-baas/desafio-dev-api-rest). | ||
|
||
## A Solução | ||
|
||
A solução é baseada no framework [Express](https://expressjs.com/pt-br/) para a interface web, e no Mapeamento Objeto Relacional (ORM) [Knex.js](https://knexjs.org/) para construção do banco de dados e de suas consultas. | ||
|
||
Para organização dos arquivos/scripts, é utilizado o [Consign](https://github.com/jarradseers/consign). | ||
|
||
## Manual de Execução | ||
|
||
A aplicação utiliza duas soluções de banco de dados dependendo do valor da variável de ambiente **NODE_ENV**. | ||
|
||
Caso a variável seja definida como _development_ (padrão), o banco de dados utilizado será SQLite, caso seja definido como _production_, o banco de dados utilizado será Postgres. | ||
|
||
No modo _development_, para executar a aplicação baste executar o _script_ **NPM** **_dev_**, que o arquivo do SQLite será criado. | ||
|
||
> npm run dev | ||
No modo _production_, além de ajustar a variável **NODE_ENV** e necessário ajustar também a variável **PG_CONNECTION_STRING** com as configurações de conexão ao banco de dados Postgres. | ||
|
||
Por exemplo: | ||
|
||
```env | ||
NODE_ENV=production | ||
PG_CONNECTION_STRING=postgres://postgres:123456@localhost:5432/banco | ||
``` | ||
|
||
> As variáveis de ambiente podem ser definidas em um arquivo **.env** no diretório raiz. | ||
### Migrações | ||
|
||
Para criar um arquivo de migração, utilize o seguinte comando: | ||
|
||
`npx knex migrate:make MIGRATION_NAME -x ts --knexfile ./src/knexfile.ts` | ||
|
||
Onde `MIGRATION_NAME` é o nome da migração | ||
|
||
> No dois caos, _development_ ou _production_, a aplicação irá realizar as migrações no banco de dados para criá-lo, conforme scripts descritos no diretório _./src/migrations_. | ||
### Seed | ||
|
||
Para criar um arquivo de migração, utilize o seguinte comando: | ||
|
||
`npx knex seed:make SEED_NAME` | ||
|
||
Onde `SEED_NAME` é o nome do arquivo seed | ||
|
||
## Criando um container para o Banco de Dados (Postgres) | ||
|
||
```shell | ||
docker run --name some-postgres -e POSTGRES_PASSWORD=123456 -e POSTGRES_USER=postgres -e POSTGRES_DB=banco -p 5432:5432 -d postgres:13 | ||
``` | ||
|
||
Onde `some-postgres` é o nome do container. |
Oops, something went wrong.