Skip to content

Bruno César Barbosa #91

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
dist
Dockerfile
.git
.dockerignore
.gitignore
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
17 changes: 16 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
#TODO Configure o Dockerfile
FROM node:20.16.0-alpine3.20

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build
RUN npm install --production

EXPOSE 3000

CMD ["npm", "run", "start"]
17 changes: 15 additions & 2 deletions init.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
USE test_db;

--TODO Crie a tabela de user;
CREATE TABLE user(
id int AUTO_INCREMENT,
firstName varchar(100) NOT NULL,
lastName varchar(100) NOT NULL,
email varchar(100) NOT NULL,
PRIMARY KEY(id)
)

--TODO Crie a tabela de posts;
CREATE TABLE post(
id int AUTO_INCREMENT,
title varchar(100) NOT NULL,
description varchar(100) NOT NULL,
userId int NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY (userId) REFERENCES user(id)
)
18 changes: 17 additions & 1 deletion src/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
import { Entity, Column, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from "./User"

//TODO Crie a entidade de Post
@Entity('post')
export class Post {
@PrimaryGeneratedColumn('increment')
id : number

@Column({ name: 'title', length: 100, nullable: false })
title : string

@Column({ name: 'description', length: 100, nullable: false })
description : string

@JoinColumn({ name: 'id' })
@OneToOne(() => User)
userId : number
}
14 changes: 14 additions & 0 deletions src/entity/User.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";

//TODO Crie a entidade de User
@Entity('user')
export class User {
@PrimaryGeneratedColumn('increment')
id: number

@Column({ name: 'firstName', length: 100, nullable: false })
firstName: string

@Column({ name: 'lastName', length: 100, nullable: false })
lastName: string

@Column({ name: 'email', length: 100, nullable: false })
email: string
}
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ const initializeDatabase = async () => {
initializeDatabase();

app.post('/users', async (req, res) => {
// Crie o endpoint de users
const user = AppDataSource.getRepository(User).create(req.body)

const result = await AppDataSource.getRepository(User).save(user)

return res.send(result)
});

app.post('/posts', async (req, res) => {
// Crie o endpoint de posts
const post = AppDataSource.getRepository(Post).create(req.body)

const result = await AppDataSource.getRepository(Post).save(post)

return res.send(result)
});

const PORT = process.env.PORT || 3000;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true
"skipLibCheck": true,
"strictPropertyInitialization": false,
},
"include": ["src/**/*", "src/db.test.ts"],
"exclude": ["node_modules"]
Expand Down