this project was inspired by this technical challenge
- npm
Requires a body like:
{
"email": "teste@teste.com",
"password": "senhaSuperSecreta"
}
Response is the data of the created user. Response example:
{
"email": "teste@teste.com",
"password": "$2b$12$5/NLktLnnai3BV/eMuZzAOl34hSh2VzCRTTlQPNfD7463lMH1P702",
"id": 1,
"createdAt": "2022-01-26T09:42:14.507Z"
}
Requires a body like:
{
"email": "teste@teste.com",
"password": "senhaSuperSecreta"
}
Response is the data of the created session. Response example:
{
"user": {
"id": 1,
"email": "teste@teste.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY0MzE5MDU2MX0.Zi2cU6NlaKML1xvCkZAfgUJKxXYGnWG4o7R1vVow4bk"
}
Requires a body like:
{
"name": "Zezinho Da Silva",
"cpf": "424.474.010-43",
"birthday": "20-02-1991",
"address": {
"cep": "04648-285",
"street": "Rua Xapanã",
"city": "São Paulo",
"number": "101",
"state": "SP",
"neighborhood": "Jardim Los Angeles",
"addressDetail": "Casa amarela" // nullable
},
"phone": "(11) 3322-1100" // Also accepts (XX) 9XXXX-XXXX
}
and a Bearer token on Authorization header.
Response is a status code 200.
Requires a Bearer token on Authorization header.
Response is the user data of the current session. Response example:
{
"id": 1,
"name": "Zezinho Da Silva",
"cpf": "424.474.010-43",
"birthday": "20-02-1991",
"phone": "(11) 3322-1100",
"userId": 1,
"address": {
"id": 1,
"cep": "04648-285",
"street": "Rua Xapanã",
"city": "São Paulo",
"number": "101",
"state": "SP",
"neighborhood": "Jardim Los Angeles",
"addressDetail": "Casa amarela",
"enrollmentId": 1
}
}
Requires a body like:
{
"number": "21184-4",
"agency": "5706"
}
, a Bearer token on Authorization header and the user must have created a enrollment.
Response is the user data of the current session. Response example:
{
"id": 1,
"number": "21184-4",
"agency": "5706",
"balance": "0.00",
"createdAt": "2022-01-26T13:08:26.443Z",
"userId": 1
}
Requires a Bearer token on Authorization header.
Response the list of accounts of the current session. Response example:
[
{
"id": 2,
"number": "21184-4",
"agency": "5706",
"balance": 0,
"createdAt": "2022-01-26T13:08:26.443Z",
"userId": 2
},
{
"id": 3,
"number": "98344-6",
"agency": "5706",
"balance": 0,
"createdAt": "2022-01-26T13:44:35.746Z",
"userId": 2
}
]
Requires a Bearer token on Authorization header.
Response the account data if it pertences the current session. Response example:
{
"id": 2,
"number": "21184-4",
"agency": "5706",
"balance": 0,
"createdAt": "2022-01-26T13:08:26.443Z",
"userId": 2
}
Requires a Bearer token on Authorization header and the account must have null balance.
Response is a status code 200.
Requires a body like:
{
"value": 0.01,
"targetAccount": {
"number": "21184-4",
"agency": "5706"
}
}
Response is the transaction record generated. Response example:
{
"description": "Deposit",
"value": 0.01,
"accountId": 2,
"id": 5,
"createdAt": "2022-01-27T09:07:45.214Z"
}
Requires a body like:
{
"value": 2.01,
"targetAccount": {
"number": "21184-4",
"agency": "5706"
}
}
, a Bearer token on Authorization header and the account must have enough balance. Response is the transaction record generated. Response example:
{
"description": "Withdraw",
"value": -2.01,
"accountId": 2,
"id": 7,
"createdAt": "2022-01-27T09:46:33.448Z"
}
Requires a body like:
{
"value": 5.50,
"targetAccount": {
"number": "98344-6",
"agency": "5706"
}
}
, a Bearer token on Authorization header and the user account must have enough balance. Response is the transaction record generated. Response example:
{
"description": "Transfer to 5706 98344-6",
"value": -5.5,
"accountId": 2,
"id": 8,
"createdAt": "2022-01-28T05:25:11.659Z"
}
- Clone this repository
- Install all dependencies
npm i
- Create a PostgreSQL database with whatever name you want
- Configure the
.env
file using the.env.example
file - Run all migrations
npm run migration:run
- Create a test PostgreSQL database using the other as template
CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser;
- Configure the
.env.test
file using the.env.example
file - Run the back-end in a development environment:
npm run dev
- Or build it and run it in production environment:
npm run build
npm start
dev
: runs the back-end in development mode, watching file changes (withnpm run dev
). ESLint errors will stop the back-end from runningtest
: runs the automated tests in the test database indicated on.env.test
. ESLint will try to fix errorsbuild
: generates the JavaScript version for this project (withnpm run build
). ESLint errors will stop the bundle from being createdmigration:generate
: generates new migrations from typescript in a single step (withnpm run migration:generate -- -n MigrationName
)migration:run
: runs all pending migrations (withnpm run migration:run
)eslint:fix
: runs eslint fixing everything eslint can automatically fixseed
: runs database seed files insrc/seeders
to populate database automatically (withnpm run seed
). Will prompt which seed files should run