This project be a part of bootcamp: GoStack by RocketSeat
In this challenge, new features and improvements were implemented in the previous project:
- Database integration;
- TypeOrm to creation and management of tables in the database;
- Upload csv files;
- New routes to delete transactions, and create new transactions to CSV files;
In this project, the concept of dividing the project structure was improved, which removes all responsibility for route files, such as business rules and data validation. A structure with models, repositories and services was used to divide the tasks. New folders have been created to separate the error class and configs.
Folder's structure:
POST /transactions
: This route receivetitle
,value
andtype
in the request body, being thetype
of transaction, which must be "income" for incoming (deposits) and "outcome" for outgoing (withdrawal). When registering a new transaction, it must be stored inside an object with the format as follows:
{
"id": "uuid",
"title": "Salário",
"value": 3000,
"type": "income"
}
When registering a new transaction, it must be stored within the database, having the fields
id
,title
,value
,type
,category_id
,created_at
,updated_at
. Before creating a new category, a check is made to see if a category with the same title already exists. If it exists, theid
that already exists in the database is used.
GET /transactions
: This route should return a list of all the transactions you have registered so far, together with the sum of the entries, withdrawals and total credit. This route must return an object with the following format:
{
"transactions": [
{
"id": "uuid",
"title": "Salário",
"value": 4000,
"type": "income",
"category": {
"id": "uuid",
"title": "Salary",
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
{
"id": "uuid",
"title": "Freela",
"value": 2000,
"type": "income",
"category": {
"id": "uuid",
"title": "Others",
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
{
"id": "uuid",
"title": "Pagamento da fatura",
"value": 4000,
"type": "outcome",
"category": {
"id": "uuid",
"title": "Others",
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
{
"id": "uuid",
"title": "Cadeira Gamer",
"value": 1200,
"type": "outcome",
"category": {
"id": "uuid",
"title": "Recreation",
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
},
"created_at": "2020-04-20T00:00:49.620Z",
"updated_at": "2020-04-20T00:00:49.620Z",
}
],
"balance": {
"income": 6000,
"outcome": 5200,
"total": 800
}
}
-
DELETE /transactions/:id
: This route must delete a transaction with the id present in theroute params
; -
POST /transactions/import
: The route should allow the import of a file in .csv format that contains the same information needed to create a transaction,id
,title
,value
,type
,category_id
,created_at
,updated_at
, in which each line of the CSV file must be a new record for the database and finally return all transactions that have been imported into the database;
To run on the first time, into your folder:
$ git clone https://github.com/Fred-Reis/challenge_backEnd-05_GoStack-v2
Into repo folder, to install Node_Modules
run:
yarn
And to start the server:
yarn dev:server
Recommend using Insomnia to test routes and DBeaver to manager your databases.
😃 Now run this project and... BE HAPPY.