Skip to content

Commit

Permalink
🚧 work in progress - labook
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleAntunes committed May 1, 2023
1 parent ffbf4b9 commit a41a5f0
Show file tree
Hide file tree
Showing 13 changed files with 4,632 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
.DS_Store
*.db
4,499 changes: 4,499 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions package.json
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"
}
}
18 changes: 18 additions & 0 deletions src/database/BaseDatabase.ts
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);
},
},
});
}
34 changes: 34 additions & 0 deletions src/database/projetoBack_End.sql
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;
7 changes: 7 additions & 0 deletions src/errors/BadRequestError.ts
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);
}
}
5 changes: 5 additions & 0 deletions src/errors/BaseError.ts
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);
}
}
9 changes: 9 additions & 0 deletions src/errors/NotFoundError.ts
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);
}
}
14 changes: 14 additions & 0 deletions src/index.ts
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 added src/router/PostRouter.ts
Empty file.
Empty file added src/router/UserRouter.ts
Empty file.
Empty file added src/types.ts
Empty file.
14 changes: 14 additions & 0 deletions tsconfig.json
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
}
}

0 comments on commit a41a5f0

Please sign in to comment.