From cbf6b9798da600b38d44c97f893c46a63dabd25c Mon Sep 17 00:00:00 2001 From: Digoleira Date: Mon, 27 Jun 2022 00:03:27 -0300 Subject: [PATCH] Inicio do Projeto --- modulo5/to-do-list/.gitignore | 4 +++ modulo5/to-do-list/package.json | 28 +++++++++++++++++++++ modulo5/to-do-list/src/app.ts | 20 +++++++++++++++ modulo5/to-do-list/src/connection.ts | 19 ++++++++++++++ modulo5/to-do-list/src/endpoints/createUser | 22 ++++++++++++++++ modulo5/to-do-list/src/index.ts | 0 modulo5/to-do-list/tsconfig.json | 14 +++++++++++ 7 files changed, 107 insertions(+) create mode 100644 modulo5/to-do-list/.gitignore create mode 100644 modulo5/to-do-list/package.json create mode 100644 modulo5/to-do-list/src/app.ts create mode 100644 modulo5/to-do-list/src/connection.ts create mode 100644 modulo5/to-do-list/src/endpoints/createUser create mode 100644 modulo5/to-do-list/src/index.ts create mode 100644 modulo5/to-do-list/tsconfig.json diff --git a/modulo5/to-do-list/.gitignore b/modulo5/to-do-list/.gitignore new file mode 100644 index 0000000..8ece3ba --- /dev/null +++ b/modulo5/to-do-list/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/modulo5/to-do-list/package.json b/modulo5/to-do-list/package.json new file mode 100644 index 0000000..0b6af17 --- /dev/null +++ b/modulo5/to-do-list/package.json @@ -0,0 +1,28 @@ +{ + "name": "aula-knex", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "start": "tsc && node ./build/index.js", + "dev-start": "ts-node-dev ./src/index.ts" + }, + "author": "Labenu", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^8.6.0", + "express": "^4.18.1" + }, + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/express": "^4.17.13", + "@types/knex": "^0.16.1", + "@types/node": "^14.14.35", + "knex": "^2.1.0", + "mysql": "^2.18.1", + "ts-node-dev": "^1.1.8", + "typescript": "^4.7.4" + }, + "keywords": [], + "description": "" +} diff --git a/modulo5/to-do-list/src/app.ts b/modulo5/to-do-list/src/app.ts new file mode 100644 index 0000000..495ce9d --- /dev/null +++ b/modulo5/to-do-list/src/app.ts @@ -0,0 +1,20 @@ +import express from "express"; +import cors from "cors"; +import { AddressInfo } from "net"; + + +const app = express(); + +app.use(express.json()); +app.use(cors()); + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost:${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); + +export default app \ No newline at end of file diff --git a/modulo5/to-do-list/src/connection.ts b/modulo5/to-do-list/src/connection.ts new file mode 100644 index 0000000..f146eba --- /dev/null +++ b/modulo5/to-do-list/src/connection.ts @@ -0,0 +1,19 @@ +import knex from "knex"; +import dotenv from "dotenv"; + + +dotenv.config(); + +const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: 3306, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA, + multipleStatements: true + }, +}); + +export default connection \ No newline at end of file diff --git a/modulo5/to-do-list/src/endpoints/createUser b/modulo5/to-do-list/src/endpoints/createUser new file mode 100644 index 0000000..b231246 --- /dev/null +++ b/modulo5/to-do-list/src/endpoints/createUser @@ -0,0 +1,22 @@ +import {Request, Response} from "express" +import connection from "../connection" + + + + + + +export const addUser = async (req: Request, res: Response) => { + + + try { + await connection("user") + + res.send("Ok"); + } catch(e) { + console.error({e}); + return res.status(500).send("Algo deu errado."); + } +}; + + diff --git a/modulo5/to-do-list/src/index.ts b/modulo5/to-do-list/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/modulo5/to-do-list/tsconfig.json b/modulo5/to-do-list/tsconfig.json new file mode 100644 index 0000000..b6574ed --- /dev/null +++ b/modulo5/to-do-list/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "outDir": "./build", + "rootDir": "./src", + "removeComments": true, + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } +} \ No newline at end of file