forked from labenuexercicios/projeto-labook-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffbf4b9
commit a41a5f0
Showing
13 changed files
with
4,632 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
build | ||
.DS_Store | ||
*.db |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "arquitetura-revisao-template", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node ./build/index.js", | ||
"build": "tsc", | ||
"dev": "ts-node-dev ./src/index.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/cors": "^2.8.13", | ||
"@types/express": "^4.17.15", | ||
"@types/knex": "^0.16.1", | ||
"@types/node": "^18.11.18", | ||
"ts-node-dev": "^2.0.0", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"express": "^4.18.2", | ||
"knex": "^2.4.2", | ||
"sqlite3": "^5.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { knex } from "knex"; | ||
|
||
export abstract class BaseDatabase { | ||
protected static connection = knex({ | ||
client: "sqlite3", | ||
connection: { | ||
filename: "./src/database/projetoBack_End.db", | ||
}, | ||
useNullAsDefault: true, | ||
pool: { | ||
min: 0, | ||
max: 1, | ||
afterCreate: (conn: any, cb: any) => { | ||
conn.run("PRAGMA foreign_keys = ON", cb); | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- Active: 1682949688943@@127.0.0.1@3306 | ||
CREATE TABLE users ( | ||
id TEXT PRIMARY KEY UNIQUE NOT NULL, | ||
name TEXT NOT NULL, | ||
email TEXT NOT NULL, | ||
password TEXT NOT NULL, | ||
created_at TEXT DEFAULT (DATETIME()) NOT NULL | ||
); | ||
|
||
CREATE TABLE | ||
posts ( | ||
id TEXT PRIMARY KEY UNIQUE NOT NULL, | ||
content TEXT NOT NULL, | ||
likes INTEGER DEFAULT(0) NOT NULL, | ||
dislikes INTEGER DEFAULT(0) NOT NULL, | ||
created_at TEXT DEFAULT (DATETIME()) NOT NULL, | ||
updated_at TEXT DEFAULT (DATETIME()) NOT NULL, | ||
creator_id TEXT NOT NULL, | ||
FOREIGN KEY (creator_id) REFERENCES users(id) | ||
); | ||
CREATE TABLE | ||
likes_dislikes ( | ||
user_id TEXT NOT NULL, | ||
post_id TEXT NOT NULL, | ||
like INTEGER DEFAULT (0) NOT NULL, | ||
FOREIGN KEY (user_id) REFERENCES users (id), | ||
FOREIGN KEY (post_id) REFERENCES posts (id) | ||
); | ||
|
||
SELECT * FROM users; | ||
|
||
SELECT * FROM posts; | ||
|
||
SELECT * FROM likes_dislikes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BaseError } from "./BaseError"; | ||
|
||
export class BadRequestError extends BaseError { | ||
constructor(message: string = "Dados inválidos") { | ||
super(400, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export abstract class BaseError extends Error { | ||
constructor(public statusCode: number, message: string) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BaseError } from "./BaseError"; | ||
|
||
export class NotFoundError extends BaseError { | ||
constructor( | ||
message: string = "Recurso não encontrado" // mensagem de erro padrão caso não seja enviado um argumento | ||
) { | ||
super(404, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import express from "express"; | ||
import cors from "cors"; | ||
|
||
// import { userRouter } from "./router/userRouter"; | ||
// import { accountRouter } from "./router/accountRouter"; | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
app.use(express.json()); | ||
|
||
app.listen(3003, () => { | ||
console.log(`Servidor rodando na porta ${3003}`); | ||
}); |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"sourceMap": true, | ||
"outDir": "./build", | ||
"rootDir": "./src", | ||
"removeComments": true, | ||
"noImplicitAny": true, | ||
"esModuleInterop": true, | ||
"noEmitOnError": true, | ||
"strict": true | ||
} | ||
} |