From 6fa2cd7d9e6bfdcac97d30c04eefd94a87d46986 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 02:13:21 -0300 Subject: [PATCH 1/7] changed the .env stuff --- .vercelignore | 5 +++ src/server/repository/todo.ts | 78 ----------------------------------- tsconfig.json | 75 ++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 107 deletions(-) create mode 100644 .vercelignore delete mode 100644 src/server/repository/todo.ts diff --git a/.vercelignore b/.vercelignore new file mode 100644 index 0000000..fc57252 --- /dev/null +++ b/.vercelignore @@ -0,0 +1,5 @@ +.github +.vscode +cypress +core +terraform diff --git a/src/server/repository/todo.ts b/src/server/repository/todo.ts deleted file mode 100644 index c829300..0000000 --- a/src/server/repository/todo.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - read, - create, - update, - deleteById as dbDeleteById, -} from '@/db-crud-todo'; -import { HttpNotFoundError } from '../infra'; - -interface TodoRepositoryGetParams { - page?: number; - limit?: number; -} -interface TodoRepositoryGetOutput { - todos: Todo[]; - total: number; - pages: number; -} - -const get = ({ - page, - limit, -}: TodoRepositoryGetParams = {}): TodoRepositoryGetOutput => { - const currentPage = page || 2; - const currentLimit = limit || 2; - const allTodos = read().reverse(); - - const startIndex = (currentPage - 1) * currentLimit; - const endIndex = currentPage * currentLimit; - const paginatedTudos = allTodos.slice(startIndex, endIndex); - const totalPages = Math.ceil(allTodos.length / currentLimit); - return { - total: allTodos.length, - pages: totalPages, - todos: paginatedTudos, - }; -}; - -const createContent = async (content: string): Promise => { - const newTodo = await create(content); - return newTodo; -}; - -const toggleDone = async (id: string): Promise => { - const allTodos = read(); - const todo = allTodos.find((todo) => todo.id === id); - - if (!todo) throw new Error(`Todo with id "${id}" not found`); - - const updatedTodo = await update(todo.id, { - done: !todo.done, - }); - - return updatedTodo; -}; - -const deleteById = async (id: string) => { - const allTodos = read(); - const todo = allTodos.find((todo) => todo.id === id); - if (!todo) throw new HttpNotFoundError(`Todo with id "${id}" not found`); - - // TODO Call the deleteById from CRUD/core - - dbDeleteById(id); -}; -export const todoRepository = { - get, - createContent, - toggleDone, - deleteById, -}; - -// Model -interface Todo { - id: string; - content: string; - date: string; - done: boolean; -} diff --git a/tsconfig.json b/tsconfig.json index 224d3b2..9e425f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,31 +1,48 @@ { - "compilerOptions": { - "target": "es2016", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "noEmit": true, - "incremental": true, - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve", - "baseUrl": ".", - "paths": { - "@/ui/*": ["src/ui/*"], - "@/server/*": ["src/server/*"], - "@/db-crud-todo": ["core/crud.ts"] - }, - "plugins": [ - { - "name": "next" - } - ] + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "noEmit": true, + "incremental": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "baseUrl": ".", + "paths": { + "@/ui/*": [ + "src/ui/*" + ], + "@/server/*": [ + "src/server/*" + ], + "@/db-crud-todo/*": [ + "core/*" + ] }, - "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] -} + "plugins": [ + { + "name": "next" + } + ] + }, + "include": [ + "next-env.d.ts", + ".next/types/**/*.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file From 8dab80141e629598863b5444845079f7229fad37 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 02:20:09 -0300 Subject: [PATCH 2/7] cd --- .github/{ => workflows}/continuous-delivery.yml | 0 .gitignore | 1 + 2 files changed, 1 insertion(+) rename .github/{ => workflows}/continuous-delivery.yml (100%) diff --git a/.github/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml similarity index 100% rename from .github/continuous-delivery.yml rename to .github/workflows/continuous-delivery.yml diff --git a/.gitignore b/.gitignore index 40498dd..c5cb6e7 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,7 @@ web_modules/ .env.test.local .env.production.local .env.local +.env.template # parcel-bundler cache (https://parceljs.org/) .cache From ab2c03b55e62c89ebbce6aa788a1caf7632556cd Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 03:00:11 -0300 Subject: [PATCH 3/7] testing --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2d410cf..9248455 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start:crud": "npx ts-node ./core/crud.ts", "dev:crud": "nodemon --ext ts,tsx --exec 'yarn start'", "dev": "next dev", - "build": "next build", + "build": "prisma generate && next build", "start": "next start", "lint": "eslint './**/*.{jsx,jsx,ts,tsx}'", "lint:fix": "yarn lint --fix", @@ -55,4 +55,4 @@ "uuid": "^9.0.0", "zod": "^3.22.2" } -} +} \ No newline at end of file From 4c276001b330342828d9aec85ef1ba92add5bfd1 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 08:22:30 -0300 Subject: [PATCH 4/7] changed terraform --- terraform/main.tf | 23 ++++++++++++---------- terraform/terraform.tfstate | 31 +++++++++++++++++++++++++++--- terraform/terraform.tfstate.backup | 8 ++++---- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index c376ed8..830b6b4 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -10,15 +10,18 @@ terraform { provider "aws" { region = "us-east-1" } - +data "aws_security_group" "public_port" { + id = "sg-0225c9598f4f0cd8f" +} resource "aws_db_instance" "default" { - allocated_storage = 10 - db_name = "study" - engine = "postgres" - engine_version = "15.3" - instance_class = "db.t3.micro" - username = "postgres" - password = "9ad3fa01-de19-4a7c-ac71-a3eb8271c056" - publicly_accessible = true - skip_final_snapshot = true + allocated_storage = 10 + db_name = "study" + engine = "postgres" + engine_version = "15.3" + instance_class = "db.t3.micro" + username = "postgres" + password = "9ad3fa01-de19-4a7c-ac71-a3eb8271c056" + publicly_accessible = true + vpc_security_group_ids = [data.aws_security_group.public_port.id] + skip_final_snapshot = true } diff --git a/terraform/terraform.tfstate b/terraform/terraform.tfstate index 61e7cf8..54fedcd 100644 --- a/terraform/terraform.tfstate +++ b/terraform/terraform.tfstate @@ -1,10 +1,32 @@ { "version": 4, "terraform_version": "1.5.4", - "serial": 5, + "serial": 7, "lineage": "10ca8984-0b45-e522-331f-d8f2514ff7e6", "outputs": {}, "resources": [ + { + "mode": "data", + "type": "aws_security_group", + "name": "public_port", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:675744721428:security-group/sg-0225c9598f4f0cd8f", + "description": "acesso ao banco de dados", + "filter": null, + "id": "sg-0225c9598f4f0cd8f", + "name": "dbInbound", + "tags": {}, + "timeouts": null, + "vpc_id": "vpc-03de2156d329a184d" + }, + "sensitive_attributes": [] + } + ] + }, { "mode": "managed", "type": "aws_db_instance", @@ -89,11 +111,14 @@ "timezone": "", "username": "postgres", "vpc_security_group_ids": [ - "sg-011c95960655a8c1e" + "sg-0225c9598f4f0cd8f" ] }, "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoyNDAwMDAwMDAwMDAwLCJkZWxldGUiOjM2MDAwMDAwMDAwMDAsInVwZGF0ZSI6NDgwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMiJ9" + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoyNDAwMDAwMDAwMDAwLCJkZWxldGUiOjM2MDAwMDAwMDAwMDAsInVwZGF0ZSI6NDgwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMiJ9", + "dependencies": [ + "data.aws_security_group.public_port" + ] } ] } diff --git a/terraform/terraform.tfstate.backup b/terraform/terraform.tfstate.backup index be788f8..61e7cf8 100644 --- a/terraform/terraform.tfstate.backup +++ b/terraform/terraform.tfstate.backup @@ -1,7 +1,7 @@ { "version": 4, "terraform_version": "1.5.4", - "serial": 3, + "serial": 5, "lineage": "10ca8984-0b45-e522-331f-d8f2514ff7e6", "outputs": {}, "resources": [ @@ -36,7 +36,7 @@ "deletion_protection": false, "domain": "", "domain_iam_role_name": "", - "enabled_cloudwatch_logs_exports": null, + "enabled_cloudwatch_logs_exports": [], "endpoint": "terraform-20231010041006281000000001.c5wea3nooocc.us-east-1.rds.amazonaws.com:5432", "engine": "postgres", "engine_version": "15.3", @@ -70,7 +70,7 @@ "performance_insights_kms_key_id": "", "performance_insights_retention_period": 0, "port": 5432, - "publicly_accessible": false, + "publicly_accessible": true, "replica_mode": "", "replicas": [], "replicate_source_db": "", @@ -83,7 +83,7 @@ "storage_encrypted": false, "storage_throughput": 0, "storage_type": "gp2", - "tags": null, + "tags": {}, "tags_all": {}, "timeouts": null, "timezone": "", From 97356039f55f8c51c241aab728dde57f07afc7a1 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 22:04:40 -0300 Subject: [PATCH 5/7] added vercel token THAT WILL BE DESTROYED ASAP --- .github/workflows/continuous-delivery.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index d5f69f7..59df9d5 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -19,4 +19,4 @@ jobs: - name: "Install Dependencies" run: "npm install" - name: "Publish to Vercel" - run: "npx vercel --prod" + run: "npx vercel --prod --token=c2JS23XHGpIQLMekiTNbAy08" From 3118a4241332cb835edb775c58213f1443e05fe1 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 22:09:13 -0300 Subject: [PATCH 6/7] added vercel token THAT WILL BE DESTROYED ASAP --- .github/workflows/continuous-delivery.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 59df9d5..4ae8785 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -6,7 +6,10 @@ name: "[CD] Continuous Delivery" on: pull_request: types: [opened, synchronize] - +env: + VERCEL_TOKEN: c2JS23XHGpIQLMekiTNbAy08 + VERCEL_ORG_ID: team_LQQ8EA13GiS1PZApkHKSIck9 + VERCEL_PROJECT_ID: prj_JdHzBfznmrwQTqsldULnikdWXD7b jobs: deploy: runs-on: ubuntu-latest @@ -19,4 +22,4 @@ jobs: - name: "Install Dependencies" run: "npm install" - name: "Publish to Vercel" - run: "npx vercel --prod --token=c2JS23XHGpIQLMekiTNbAy08" + run: "npx vercel --prod" From 8b916af8cccfc8bd6ec0b89a95145df984b151e3 Mon Sep 17 00:00:00 2001 From: Tiago Date: Tue, 10 Oct 2023 22:10:46 -0300 Subject: [PATCH 7/7] added vercel token THAT WILL BE DESTROYED ASAP --- .github/workflows/continuous-delivery.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 4ae8785..4c6b15b 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -7,7 +7,6 @@ on: pull_request: types: [opened, synchronize] env: - VERCEL_TOKEN: c2JS23XHGpIQLMekiTNbAy08 VERCEL_ORG_ID: team_LQQ8EA13GiS1PZApkHKSIck9 VERCEL_PROJECT_ID: prj_JdHzBfznmrwQTqsldULnikdWXD7b jobs: @@ -22,4 +21,4 @@ jobs: - name: "Install Dependencies" run: "npm install" - name: "Publish to Vercel" - run: "npx vercel --prod" + run: "npx vercel --prod --token=c2JS23XHGpIQLMekiTNbAy08"