Skip to content

Commit

Permalink
Criando conexão com o BD - User
Browse files Browse the repository at this point in the history
  • Loading branch information
JaquelineVictal committed Nov 9, 2022
1 parent db4e235 commit 17382f9
Show file tree
Hide file tree
Showing 16 changed files with 419 additions and 30 deletions.
Empty file added logs/error.log
Empty file.
Empty file added logs/info.log
Empty file.
113 changes: 84 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
},
"homepage": "https://github.com/thiagodrodrigues/Prontuario-Digital#readme",
"dependencies": {
"@types/bcrypt": "^5.0.0",
"@types/cookie-parser": "^1.4.3",
"bcrypt": "^5.1.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"debug": "^4.3.4",
"express": "^4.18.2",
"express-winston": "^4.2.0",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.25.4",
"sequelize": "^6.25.5",
"sequelize-typescript": "^2.1.5",
"winston": "^3.8.2"
},
Expand Down
62 changes: 62 additions & 0 deletions src/infrastructure/app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import express from "express";
import * as http from "http";

import * as winston from "winston";
import * as expressWinston from "express-winston";
import cors from "cors";
import{ debug } from "debug";

import { UserRoutes } from "../../adapters/apis/routes/users.routes.config";
import { CommonRoutesConfig } from "../../adapters/apis/routes/common.routes.config";
import path from "path";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";

const app: express.Application = express();
const server: http.Server = http.createServer();
const PORT = process.env.PORT || 8000;
const routes: CommonRoutesConfig[] = [];
const debugLog: debug.IDebugger = debug('app');

app.use(express.json());
app.use(express.urlencoded());
app.use(cors());
app.use('/uploads', express.static(path.resolve('uploads')))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : false}));
app.use(cookieParser());

const loggerOptions: expressWinston.LoggerOptions = {
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.json(),
winston.format.prettyPrint(),
winston.format.colorize({ all: true })
),
}
if(!process.env.DEBUG) {
loggerOptions.meta = false;
}

app.use(expressWinston.logger(loggerOptions));

routes.push(new UserRoutes(app));


let runningMessage = `Servidor rodando na porta ${PORT}`;

try {
app.get('/', (request: express.Request, response: express.Response) => {
response.status(200).send(runningMessage);
})
} catch (error) {
console.error(error);
}

app.listen(PORT, () => {
routes.forEach((route: CommonRoutesConfig)=>{
debugLog(`Rota ${route.getName()} configurada com sucesso!}`);
});
console.log(runningMessage)});

export default app;
15 changes: 15 additions & 0 deletions src/infrastructure/config/db.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dotenv/config';

const dbConfig = {
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
dialect: 'mysql',
}


export default dbConfig;

module.exports = dbConfig;
5 changes: 5 additions & 0 deletions src/infrastructure/config/getErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message;
return String(error);
}

9 changes: 9 additions & 0 deletions src/infrastructure/persistence/database.model.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IDatabase } from "./databese.interface";

export interface IDatabaseModel extends IDatabase {
createModel(name: string, properties: any): any,
read(type: any, dataId: number, includes?: object): any,
list(type: any, includes?: object): any,
readByWhere(type: any, data: any):any,
selectQuery(sql:string,replacements:any):any
}
7 changes: 7 additions & 0 deletions src/infrastructure/persistence/databese.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface IDatabase{
list(type: any, dataWhere?:any): any[];
create(type: any, data: any): any,
read(type: any, dataId:number): any,
update(type : any, data: any): any,
delete(type: any, dataId:any): any
}
Loading

0 comments on commit 17382f9

Please sign in to comment.