Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refatoração de Projeto TypeScript para NestJS #108

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e872c71
setup: Migrated NestJS
titi0001 Nov 17, 2024
94040d3
chore: update for NestJS migration
titi0001 Nov 17, 2024
fad4f7e
Feat: add Docker and DB config files
titi0001 Nov 17, 2024
9baa814
Chore: remove BKP docker and SQL config files
titi0001 Nov 17, 2024
fec268d
Feat: Add user and post modules app.module configuration
titi0001 Nov 17, 2024
ba3e758
Chore: install @nestjs/config and update main.ts for dotenv integration
titi0001 Nov 17, 2024
458fe6f
refactor: Remove incorrectly created service.module.ts and update pos…
titi0001 Nov 17, 2024
021c063
refactor: Remove unused AppController/AppService, update AppModule-Po…
titi0001 Nov 17, 2024
2fd2a6e
feat: config db connection with AppDataSource and integrate it into A…
titi0001 Nov 17, 2024
1d8f6de
chore: remove BKP and legacy files
titi0001 Nov 17, 2024
44a0e03
Chore: update docker-compose to use .env
titi0001 Nov 17, 2024
910ea0b
refactor: improve appDataSource logic with .env integration
titi0001 Nov 17, 2024
e61bef5
feat: create post and user entities
titi0001 Nov 17, 2024
8cf856d
feat: update user and post modules with entity integration
titi0001 Nov 17, 2024
6a5d420
feat: add db creation and table definitions in init.sql script
titi0001 Nov 17, 2024
ef6df36
feat: install class-validator
titi0001 Nov 17, 2024
96aa1f2
feat: add DTO´s for user and post validation
titi0001 Nov 17, 2024
cad7ef8
refactor: update controllers and services for user and post modules
titi0001 Nov 17, 2024
ba40cc4
refactor: update main.ts to align to validate
titi0001 Nov 17, 2024
963f57b
chore: remove obsolete test and service files
titi0001 Nov 17, 2024
6570293
refactor: configure AppModule for updated NestJS structure
titi0001 Nov 17, 2024
5ef5953
chore: adjust Dockerfile for NestJS setup and environment configuration
titi0001 Nov 17, 2024
d6600dc
chore: update docker-compose.yml with container names and volumes
titi0001 Nov 18, 2024
1bac5dd
chore: add necessary scripts test
titi0001 Nov 18, 2024
a6ac56f
test: add end-to-end test for user and post creation
titi0001 Nov 18, 2024
51a7164
refactor: improve database connection management
titi0001 Nov 18, 2024
765078a
refactor: adjust CLI for database initialization
titi0001 Nov 18, 2024
0fbdf26
refactor: delegate database initialization to DatabaseService and int…
titi0001 Nov 18, 2024
df81328
refactor: remove dotenv to main.ts
titi0001 Nov 18, 2024
068ab86
feat: add DBService for centralized DB initialization and logging
titi0001 Nov 18, 2024
0d88289
feat: add run-tests.sh script for automated Docker setup and testing
titi0001 Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
#TODO Configure o Dockerfile
FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

RUN npm install -g @nestjs/cli

COPY . .

EXPOSE 3000

CMD ["npm", "run", "start:dev"]
117 changes: 78 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,99 @@
# Descrição do Teste para a Vaga de Desenvolvedor Jr.
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

## Contextualização do Desafio
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

Este teste foi desenvolvido para avaliar suas habilidades práticas em tarefas comuns do dia a dia de um desenvolvedor júnior. Através deste desafio, você terá a oportunidade de demonstrar seu conhecimento na criação de banco de dados, definição de relacionamentos entre tabelas e entidades, além de aplicar boas práticas de desenvolvimento em um ambiente Docker. O objetivo é simular uma situação real de desenvolvimento de uma aplicação simples, onde você deverá criar as estruturas necessárias e garantir que o sistema esteja funcionando corretamente por meio de testes. A conclusão bem-sucedida desta tarefa refletirá seu domínio de conceitos importantes para a vaga.
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## 1º Passo: Criação das Tabelas no `init.sql`
## Description

Dentro do arquivo `init.sql`, crie as seguintes tabelas:
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

### Tabela `user`
- **id** – Tipo: `Int`, autoincremental, chave primária (PK).
- **firstName** – Tipo: `Varchar(100)`, não nulo.
- **lastName** – Tipo: `Varchar(100)`, não nulo.
- **email** – Tipo: `Varchar(100)`, não nulo.
## Project setup

### Tabela `post`
- **id** – Tipo: `Int`, autoincremental, chave primária (PK).
- **title** – Tipo: `Varchar(100)`, não nulo.
- **description** – Tipo: `Varchar(100)`, não nulo.
- **userId** – Tipo: `Int`, não nulo (chave estrangeira referenciando a tabela `user`).
```bash
$ npm install
```

---
## Compile and run the project

## 2º Passo: Criação das Entidades `User` e `Post`
```bash
# development
$ npm run start

Dentro da pasta `src/Entity`, crie as entidades correspondentes às tabelas `User` e `Post`.
# watch mode
$ npm run start:dev

---
# production mode
$ npm run start:prod
```

## 3º Passo: Configurar endpoints `users` e `posts`
## Run tests

Dentro de `src/index.ts`, configure dois endpoints `users` & `posts`
```bash
# unit tests
$ npm run test

---
# e2e tests
$ npm run test:e2e

## 4º Passo: Configuração do Dockerfile
# test coverage
$ npm run test:cov
```

Configure o `Dockerfile` da aplicação para garantir que ela seja construída corretamente no ambiente Docker.
## Deployment

---
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.

## 5º Passo: Teste da Aplicação
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

Execute os seguintes comandos para testar a aplicação:
```bash
$ npm install -g mau
$ mau deploy
```

1. **Subir a aplicação utilizando Docker Compose**:
```bash
docker compose up --build
docker exec -it <Container Name> /bin/sh

```
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

Dentro do container, execute o teste:
```bash
npm test
```
## Resources

## 6º Passo: Crie um fork desse repositório e submita o código preenchido nele.
Crie um Pull Request para a brach master nos enviando o código
Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
16 changes: 7 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
version: '3.8'

services:
api:
build: .
container_name: api-container
ports:
- "3000:3000"
environment:
- DB_HOST=db
- DB_USER=root
- DB_PASSWORD=password
- DB_NAME=test_db
- DB_HOST=${DB_HOST}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
depends_on:
- db


db:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=test_db
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
ports:
- "3306:3306"
volumes:
Expand Down
16 changes: 14 additions & 2 deletions init.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
CREATE DATABASE IF NOT EXISTS test_db;
USE test_db;

--TODO Crie a tabela de user;
CREATE TABLE IF NOT EXISTS user (
id INT AUTO_INCREMENT PRIMARY KEY,
firstName VARCHAR(100) NOT NULL,
lastName VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL
);

--TODO Crie a tabela de posts;
CREATE TABLE IF NOT EXISTS post (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
description VARCHAR(100) NOT NULL,
userId INT NOT NULL,
FOREIGN KEY (userId) REFERENCES user(id) ON DELETE CASCADE
);
8 changes: 8 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading