Skip to content

Commit

Permalink
Release 2024-02-18 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueleite42 authored Feb 19, 2024
2 parents 9c3dbae + 0f514e4 commit 700f436
Show file tree
Hide file tree
Showing 138 changed files with 8,407 additions and 545 deletions.
1 change: 1 addition & 0 deletions .github/workflows/api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- release
paths:
- 'src/**'
workflow_dispatch:

jobs:
build-deploy:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/tests-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: tests-validate

on:
pull_request:
branches:
- master
paths:
- 'src/*'
- 'tests/*'

jobs:
tests-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install dependencies
run: yarn install --ignore-scripts

- name: Run tests
run: yarn test:cov
6 changes: 5 additions & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"bash -c \"yarn openapi:postman\""
],
"prisma/**/*": "bash -c \"yarn lint:prisma\"",
"src/**/*": ["bash -c \"yarn lint:ts\"", "bash -c \"yarn lint:code\""]
"(src|tests)/**/*": [
"bash -c \"yarn lint:ts\"",
"bash -c \"yarn lint:code\"",
"bash -c \"yarn test\""
]
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@
"dtos",
"Econominhas",
"medkit",
"NANQUIM",
"nestjs",
"openapi",
"Personnalité",
"redocly",
"Usecase",
"usecases"
Expand Down
70 changes: 29 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,37 @@ This project use lot's of tools to be as efficient as possible, here's the list
- [API](https://wise-bulldog-88.redoc.ly/)
- [Database](https://dbdocs.io/henriqueleite42/Econominhas?view=relationships)

## Third party Urls

### Dev

- [Google](https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?response_type=code&client_id=489785083174-0rqt9bc7l9t09luor3fc16h21kdf57q7.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8081&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&access_type=offline&state=1234_purpleGoogle&prompt=consent&authuser=1&service=lso&o2v=2&theme=glif&flowName=GeneralOAuthFlow)

## Useful commands

| Command | Description |
| --------------- | --------------------------------------------------------------------------------------------- |
| `start:dev` | Run the project with all it's dependencies locally |
| `openapi:serve` | Serve the API docs locally so you can validate your changes |
| `db:prisma` | Update the ORM types (You need to run this every time that you change `prisma/schema.prisma`) |

## Manual Deploy

1. Connect to the EC2 instance trough [the console](https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1#InstanceDetails:instanceId=i-058e2ca9b6b405219)
2. [EC2] Stop the current execution:

```sh
pm2 stop econominhas
pm2 delete econominhas
```

3. [EC2] Delete the old files:

```
rm -rf dist
```

4. [Locally] Send the files to the EC2:

```sh
scp -i ~/Desktop/default.pem -r dist [email protected]:/home/ubuntu
```

5. [EC2] Execute the API:

```sh
cd dist
yarn
pm2 start main.js --name econominhas
```
| Command | Description |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `start:dev` | Run the project with all it's dependencies locally |
| `openapi:serve` | Serve the API docs locally so you can validate your changes |
| `openapi:postman` | Generate Postman json file (at `openapi/postman.json`) |
| `lint:prisma` | Lint prisma schema |
| `db:prisma` | Update the ORM types (You need to run this every time that you change `prisma/schema.prisma`) |
| `test` | Run tests |
| `test:cov` | Run tests and collect coverage |
| `db:migrate` | Run the migrations |
| `db:gen-migration <name>` | Generates a new migration based on the schema-database difference (you must run `start:dev` and `db:migrate` before run this!) |

## How to create a migration

- Run `yarn start:db`
- In another tab, run `yarn db:gen-migration <migration name>`

## Teams

The teams names are based on different currencies around the world, but the countries that they are used don't have any influence on the things that the teams works on.

| Team | Responsible for | Full list |
| ----- | --------------- | ------------------------------------------------------------------- |
| Real | Auth | Accounts, SignInProvider, MagicLink, RefreshToken, TermsAndPolicies |
| Franc | Profile | Configs, Salary |
| Yuan | Transactions | Transactions, Recurrent transactions |
| Peso | Cards | Cards, Card Providers, Cards Bills |
| Rand | Bank Accounts | Bank Accounts, Bank Providers, Subscriptions |
| Rupee | Budgets | Budgets, Categories |

## Process to develop a new feature

Expand Down
8 changes: 4 additions & 4 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ permissions:

hooks:
ApplicationStop:
- location: scripts/cd-stop.sh
- location: scripts/ci-cd/stop.sh
timeout: 300
runas: ubuntu

AfterInstall:
- location: scripts/cd-prepare.sh
- location: scripts/ci-cd/prepare.sh
timeout: 300
runas: ubuntu

ApplicationStart:
- location: scripts/cd-start.sh
- location: scripts/ci-cd/start.sh
timeout: 300
runas: ubuntu

ValidateService:
- location: scripts/cd-validate.sh
- location: scripts/ci-cd/validate.sh
timeout: 300
runas: ubuntu
23 changes: 19 additions & 4 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "src",
"rootDir": ".",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": ["**/*.(t|j)s"],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"collectCoverageFrom": [
"src/**/*.(t|j)s",
"!src/app.module.ts",
"!src/config.ts",
"!src/main.ts",
"!src/models/*.ts",
"!src/adapters/*.ts",
"!src/adapters/implementations/s3/*.ts",
"!src/adapters/implementations/ses/*.ts",
"!src/adapters/implementations/sns/*.ts",
"!src/repositories/postgres/*.ts",
"!src/types/**/*.ts"
],
"coverageDirectory": "./coverage",
"testEnvironment": "node",
"moduleDirectories": ["node_modules", "src"],
"setupFiles": ["./tests/setup.ts"],
"resetMocks": true
}
7 changes: 7 additions & 0 deletions openapi/components/fields/transaction-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: |
Transaction name
type: string
minLength: 1
maxLength: 30
examples:
- "Foo"
6 changes: 6 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ paths:
$ref: paths/accounts/iam.yaml
/accounts/name:
$ref: paths/accounts/name.yaml
/accounts/onboarding:
$ref: paths/accounts/onboarding.yaml

/banks/providers:
$ref: paths/banks/providers.yaml
Expand Down Expand Up @@ -122,6 +124,10 @@ paths:
$ref: paths/transactions/salary.yaml
/transactions/transfer:
$ref: paths/transactions/transfer.yaml
/transactions/in-out:
$ref: paths/transactions/in-out.yaml
/transactions/credit:
$ref: paths/transactions/credit.yaml

/wallet/balance:
$ref: paths/wallet/balance.yaml
Expand Down
41 changes: 41 additions & 0 deletions openapi/paths/accounts/onboarding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
patch:
tags:
- Account
summary: Update user's onboarding progress
description: |
Update user's onboarding progress
operationId: account-update-onboarding
security:
- bearer: []
requestBody:
content:
application/json:
schema:
type: object
title: Update user's onboarding progress
properties:
name:
type: boolean
categories:
type: boolean
bankAccounts:
type: boolean
creditCards:
type: boolean
budget:
type: boolean
salary:
type: boolean
required: true
responses:
"204":
description: |
Onboarding progress updated
"400":
description: |
Invalid name
"401":
description: |
Unauthorized
64 changes: 64 additions & 0 deletions openapi/paths/transactions/credit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
post:
tags:
- Transaction
summary: Create CREDIT transaction
description: |
Create a CREDIT transaction, to add or remove money from
one of the user's bank accounts only when the card bill
is paid
operationId: transaction-credit
security:
- bearer: []
requestBody:
content:
application/json:
schema:
type: object
required:
- name
- description
- amount
- installments
- categoryId
- cardId
- budgetDateId
- createdAt
properties:
name:
$ref: ../../components/fields/transaction-name.yaml
description:
$ref: ../../components/fields/description.yaml
amount:
$ref: ../../components/fields/amount.yaml
installments:
description: |
Amount of installments for the transaction
type: integer
minimum: 1
examples:
- 1
- 12
- 420
cardId:
description: ID of the card used to pay the transaction
type: string
format: uuid
categoryId:
description: Category ID
type: string
format: uuid
budgetDateId:
description: BudgetDate ID
type: string
format: uuid
createdAt:
$ref: ../../components/fields/created-at.yaml
required: true
responses:
"201":
description: |
Transaction created
"400":
$ref: ../../components/responses/bad-request.yaml
"401":
$ref: ../../components/responses/unauthorized.yaml
61 changes: 61 additions & 0 deletions openapi/paths/transactions/in-out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
post:
tags:
- Transaction
summary: Create IN or OUT transaction
description: |
Create a IN or OUT transaction, to add or remove money from
one of the user's bank accounts
operationId: transaction-in-out
security:
- bearer: []
requestBody:
content:
application/json:
schema:
type: object
required:
- type
- name
- amount
- bankAccountId
- budgetDateId
- categoryId
- description
- createdAt
properties:
type:
description: |
Transaction type
type: string
enum:
- IN
- OUT
name:
$ref: ../../components/fields/transaction-name.yaml
description:
$ref: ../../components/fields/description.yaml
amount:
$ref: ../../components/fields/amount.yaml
bankAccountId:
description: ID of the bank account to add/remove money
type: string
format: uuid
categoryId:
description: Category ID
type: string
format: uuid
budgetDateId:
description: BudgetDate ID
type: string
format: uuid
createdAt:
$ref: ../../components/fields/created-at.yaml
required: true
responses:
"201":
description: |
Transaction created
"400":
$ref: ../../components/responses/bad-request.yaml
"401":
$ref: ../../components/responses/unauthorized.yaml
Loading

0 comments on commit 700f436

Please sign in to comment.