Sample API for financial transaction management written in Node on an implementation of clean architecture.
The following commands are available:
Installs application dependencies.
Starts the server application locally on port 3000
.
Starts the server application on Docker on port 3000
.
Executes all available tests.
In order to get the app running, you need to run Postgres either locally or through a Docker container:
docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=password postgres
Access your Postgres instance with the command:
docker exec -it postgres psql -U postgres
And run the following instructions to get the database started:
CREATE USER "node-transactions-username" WITH PASSWORD 'node-transactions-password';
CREATE DATABASE "node-transactions" OWNER "node-transactions-username";
Optionally, you can change the values of the environment variables and update the script above accordingly.
DB_USERNAME = "node-transactions-username";
DB_PASSWORD = "node-transactions-password";
The following commands are available:
Runs all pending migrations.
Reverts performed migrations.
In order to interact with the queues, make sure you are running Redis either locally or through a Docker container:
docker run -p 6379:6379 -d redis
The following commands are available:
Starts consumer for <queue-name>
at the Redis server running on port 6379
.
npm run queue:consumer -- "account-queue"
npm run queue:consumer -- "transaction-queue"
Produces job with <json-payload>
for <queue-name>
at the Redis server running on port 6379
.
npm run queue:producer -- "account-queue" '{"document_number": "12345678900"}'
npm run queue:producer -- "transaction-queue" '{"account_id": 10, "amount": 7.77}'
Searches for an account with the provided :id
.
response:
{
"id": 1,
"document_number": "12345678900",
"balance": 123.45
}
Creates an account with the provided attributes.
request:
{
"document_number": "12345678900"
}
response:
{
"id": "1",
"document_number": "12345678900"
}
Creates a transaction with the provided attributes.
request:
{
"account_id": 1,
"amount": 123.45
}
response:
{
"id": 1,
"account_id": 1,
"amount": 123.45,
"timestamp": "2024-07-12T13:13:13.777Z"
}