From 0596c9357181cd6d65f8d1d6fed9b2e3baab5b8d Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Tue, 30 Mar 2021 20:20:32 +0100 Subject: [PATCH 01/22] Configurado projeto. --- .gitignore | 4 ++ package.json | 35 +++++++++++++++++ request.rest | 1 + src/app.ts | 18 +++++++++ src/connection.ts | 15 +++++++ src/endpoints/delete/delete.ts | 1 + src/endpoints/get/get.ts | 1 + src/endpoints/post/post.ts | 1 + src/endpoints/put/put.ts | 1 + src/index.ts | 2 + tsconfig.json | 71 ++++++++++++++++++++++++++++++++++ 11 files changed, 150 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 request.rest create mode 100644 src/app.ts create mode 100644 src/connection.ts create mode 100644 src/endpoints/delete/delete.ts create mode 100644 src/endpoints/get/get.ts create mode 100644 src/endpoints/post/post.ts create mode 100644 src/endpoints/put/put.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3343c96 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +.env +package-lock.json +build \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..bf857ab --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "epps-labenu-system8", + "version": "1.0.0", + "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", + "main": "index.js", + "scripts": { + "dev": "clear && ts-node-dev ./src/index.ts", + "start": "clear && tsc && node ./build/index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/future4code/epps-labenu-system8.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/future4code/epps-labenu-system8/issues" + }, + "homepage": "https://github.com/future4code/epps-labenu-system8#readme", + "devDependencies": { + "@types/cors": "^2.8.10", + "@types/express": "^4.17.11", + "cors": "^2.8.5", + "express": "^4.17.1", + "ts-node-dev": "^1.1.6", + "typescript": "^4.2.3" + }, + "dependencies": { + "@types/knex": "^0.16.1", + "dotenv": "^8.2.0", + "knex": "^0.95.4", + "mysql": "^2.18.1" + } +} diff --git a/request.rest b/request.rest new file mode 100644 index 0000000..7dd1349 --- /dev/null +++ b/request.rest @@ -0,0 +1 @@ +GET http://localhost:3003 \ No newline at end of file diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..fd02ebd --- /dev/null +++ b/src/app.ts @@ -0,0 +1,18 @@ +import express, {Express} from 'express' +import cors from 'cors' +import { AddressInfo } from "net"; + +const app: Express = 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/src/connection.ts b/src/connection.ts new file mode 100644 index 0000000..fc7a82e --- /dev/null +++ b/src/connection.ts @@ -0,0 +1,15 @@ +import knex from "knex"; +import dotenv from "dotenv"; + +dotenv.config(); + +export const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: Number(process.env.DB_PORT) || 3306, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME + } +}); \ No newline at end of file diff --git a/src/endpoints/delete/delete.ts b/src/endpoints/delete/delete.ts new file mode 100644 index 0000000..b9a57a1 --- /dev/null +++ b/src/endpoints/delete/delete.ts @@ -0,0 +1 @@ +//criar endpoint de delete \ No newline at end of file diff --git a/src/endpoints/get/get.ts b/src/endpoints/get/get.ts new file mode 100644 index 0000000..d13a26f --- /dev/null +++ b/src/endpoints/get/get.ts @@ -0,0 +1 @@ +//criar endpoint de get \ No newline at end of file diff --git a/src/endpoints/post/post.ts b/src/endpoints/post/post.ts new file mode 100644 index 0000000..80a848f --- /dev/null +++ b/src/endpoints/post/post.ts @@ -0,0 +1 @@ +//criar endpoint post \ No newline at end of file diff --git a/src/endpoints/put/put.ts b/src/endpoints/put/put.ts new file mode 100644 index 0000000..1a80f44 --- /dev/null +++ b/src/endpoints/put/put.ts @@ -0,0 +1 @@ +//criar endpoint put \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7358cc3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +import app from './app' + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e124967 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./build", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} From a9b4e126f2573a5e3829dfa35b3fe540c896186a Mon Sep 17 00:00:00 2001 From: Bruno-Galhardi Date: Wed, 31 Mar 2021 14:23:36 -0300 Subject: [PATCH 02/22] parte de criar estudante, professor e turma criada, junto com seus respectivos endpoints --- request.rest | 38 +++++++++++- src/GlobalFunctions/globalFunction | 1 + src/TypesAndEnums/Enums.ts | 11 ++++ src/TypesAndEnums/Types.ts | 9 +++ src/endpoints/post/createClass.ts | 27 +++++++++ src/endpoints/post/createStudant.ts | 35 +++++++++++ src/endpoints/post/createTeacher.ts | 90 +++++++++++++++++++++++++++++ src/index.ts | 6 ++ 8 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/GlobalFunctions/globalFunction create mode 100644 src/TypesAndEnums/Enums.ts create mode 100644 src/TypesAndEnums/Types.ts create mode 100644 src/endpoints/post/createClass.ts create mode 100644 src/endpoints/post/createStudant.ts create mode 100644 src/endpoints/post/createTeacher.ts diff --git a/request.rest b/request.rest index 7dd1349..9656974 100644 --- a/request.rest +++ b/request.rest @@ -1 +1,37 @@ -GET http://localhost:3003 \ No newline at end of file +GET http://localhost:3003 + +### +POST http://localhost:3003/studant/create +Content-Type: application/json + +{ + "nome":"Daniel Sacramento", + "email":"daniel@gmail.com", + "data_nasc":"2000-04-15", + "turma_id": 3, + "nomePassatempo":"codar nas madrugadas portuguesas" + +} + +#### +POST http://localhost:3003/class/create +Content-Type: application/json + +{ + "nome":"Turma IPA", + "data_inicio":"2021-10-15", + "data_final":"2022-04-23", + "modulo":"0" +} + +### +POST http://localhost:3003/teacher/create +Content-Type: application/json + +{ + "nome":"João", + "email":"joao@gmail.com", + "data_nasc":"1999-04-15", + "turma_id": 3, + "nomeEspecialidades":"backend" +} \ No newline at end of file diff --git a/src/GlobalFunctions/globalFunction b/src/GlobalFunctions/globalFunction new file mode 100644 index 0000000..27f95d9 --- /dev/null +++ b/src/GlobalFunctions/globalFunction @@ -0,0 +1 @@ +//funções do projeto! \ No newline at end of file diff --git a/src/TypesAndEnums/Enums.ts b/src/TypesAndEnums/Enums.ts new file mode 100644 index 0000000..94e610c --- /dev/null +++ b/src/TypesAndEnums/Enums.ts @@ -0,0 +1,11 @@ +export enum Especialidades{ + + REACT="react", + REDUX="redux", + CSS="css", + TESTES="testes", + TYPESCRIPT="typescript", + PROGRAMACAO_ORIENTADA_OBJETOS="programacao orientada objetos", + BACKEND="backend" + +} \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts new file mode 100644 index 0000000..0583c53 --- /dev/null +++ b/src/TypesAndEnums/Types.ts @@ -0,0 +1,9 @@ +import { Especialidades } from './Enums' + +export type Docentes = { + nome:string, + email:string, + data_nasc:string, + turma_id:number, + especialidade:Especialidades +} \ No newline at end of file diff --git a/src/endpoints/post/createClass.ts b/src/endpoints/post/createClass.ts new file mode 100644 index 0000000..a505620 --- /dev/null +++ b/src/endpoints/post/createClass.ts @@ -0,0 +1,27 @@ +import { connection } from '../../connection' +import { Request, Response } from 'express' + + +const createClass = async ( + req: Request, + res: Response +): Promise => { + try { + await connection.raw( + `INSERT INTO Turmas (nome, data_inicio, data_final, modulo) + VALUES( + "${req.body.nome}", + "${req.body.data_inicio}", + "${req.body.data_final}", + "${req.body.modulo}" + )` + ) + + res.status(201).send('Turma criada com sucesso!') + + } catch (error) { + res.status(500).send("Todos os campos devem ser preenchidos") + } +} + +export default createClass; \ No newline at end of file diff --git a/src/endpoints/post/createStudant.ts b/src/endpoints/post/createStudant.ts new file mode 100644 index 0000000..451c8ac --- /dev/null +++ b/src/endpoints/post/createStudant.ts @@ -0,0 +1,35 @@ +import { connection } from '../../connection' +import { Request, Response } from 'express' + +const createStudant = async ( + req: Request, + res: Response +): Promise => { + try { + await connection.raw( + ` + INSERT INTO Estudantes (nome, email, data_nasc, turma_id) + VALUES( + "${req.body.nome}", + "${req.body.email}", + "${req.body.data_nasc}", + "${req.body.turma_id}" + )`) + + await connection.raw( + ` + INSERT INTO Passatempo(nome) + VALUES( + "${req.body.nomePassatempo}" + ) + ` + ) + + res.status(201).send('Estudante criado com sucesso!') + + } catch (error) { + res.status(500).send("Todos os campos devem ser preenchidos") + } +} + +export default createStudant; \ No newline at end of file diff --git a/src/endpoints/post/createTeacher.ts b/src/endpoints/post/createTeacher.ts new file mode 100644 index 0000000..199bde9 --- /dev/null +++ b/src/endpoints/post/createTeacher.ts @@ -0,0 +1,90 @@ +import { connection } from '../../connection' +import { Request, Response } from 'express' +import { Especialidades } from '../../TypesAndEnums/Enums' +import { Docentes } from '../../TypesAndEnums/Types' + +const createTeacher = async ( + req: Request, + res: Response +): Promise => { + try { + await connection.raw( + ` + INSERT INTO Docentes (nome, email, data_nasc, turma_id) + VALUES( + "${req.body.nome}", + "${req.body.email}", + "${req.body.data_nasc}", + "${req.body.turma_id}" + )`) + + if(Especialidades.BACKEND === 'backend'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "Backend" + ) + ` + ) + } else if(Especialidades.CSS === 'css'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "CSS" + ) + `) + } else if (Especialidades.PROGRAMACAO_ORIENTADA_OBJETOS === 'programacao orientada objetos'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "Programacao orientada objetos" + ) + `) + } else if(Especialidades.REACT === 'react'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "React" + ) + `) + } else if(Especialidades.REDUX === 'redux'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "Redux" + ) + `) + } else if(Especialidades.TESTES === 'testes'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "Testes" + ) + `) + } else if(Especialidades.TYPESCRIPT === 'typescript'){ + await connection.raw( + ` + INSERT INTO Especialidade(nome) + VALUES( + "Typescript" + ) + `) + } else{ + throw new Error('Especialidade inválida: Especialidades suportadas: Backend, Css, Programacao Orientada Objeto, React, Redux, Testes, Typescript') + } + + + res.status(201).send('Professor criado com sucesso!') + + } catch (error) { + res.status(500).send("Todos os campos devem ser preenchidos") + } +} + +export default createTeacher; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 7358cc3..2362d5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,8 @@ import app from './app' +import createClass from './endpoints/post/createClass' +import createStudant from './endpoints/post/createStudant' +import createTeacher from './endpoints/post/createTeacher' +app.post ('/class/create', createClass) +app.post('/studant/create', createStudant) +app.post ('/teacher/create', createTeacher) From 82662a705b8351f9f5a9d8ea8219904330cfd120 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Wed, 31 Mar 2021 21:19:53 +0100 Subject: [PATCH 03/22] Implementado funcionalidade de troca de turma. --- request.rest | 21 ++++++++--- src/GlobalFunctions/updateClass.ts | 10 +++++ src/TypesAndEnums/Enums.ts | 5 +++ src/TypesAndEnums/Types.ts | 8 +++- src/endpoints/{ => class}/post/createClass.ts | 2 +- src/endpoints/post/post.ts | 1 - src/endpoints/{ => studant}/delete/delete.ts | 0 src/endpoints/{ => studant}/get/get.ts | 0 .../{ => studant}/post/createStudant.ts | 6 +-- src/endpoints/{ => studant}/put/put.ts | 0 .../{ => teacher}/post/createTeacher.ts | 6 +-- src/endpoints/teacher/put/changeClass.ts | 37 +++++++++++++++++++ src/index.ts | 8 ++-- 13 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 src/GlobalFunctions/updateClass.ts rename src/endpoints/{ => class}/post/createClass.ts (93%) delete mode 100644 src/endpoints/post/post.ts rename src/endpoints/{ => studant}/delete/delete.ts (100%) rename src/endpoints/{ => studant}/get/get.ts (100%) rename src/endpoints/{ => studant}/post/createStudant.ts (84%) rename src/endpoints/{ => studant}/put/put.ts (100%) rename src/endpoints/{ => teacher}/post/createTeacher.ts (94%) create mode 100644 src/endpoints/teacher/put/changeClass.ts diff --git a/request.rest b/request.rest index 9656974..88ed1ac 100644 --- a/request.rest +++ b/request.rest @@ -8,9 +8,8 @@ Content-Type: application/json "nome":"Daniel Sacramento", "email":"daniel@gmail.com", "data_nasc":"2000-04-15", - "turma_id": 3, + "turma_id": 1, "nomePassatempo":"codar nas madrugadas portuguesas" - } #### @@ -18,10 +17,10 @@ POST http://localhost:3003/class/create Content-Type: application/json { - "nome":"Turma IPA", - "data_inicio":"2021-10-15", - "data_final":"2022-04-23", - "modulo":"0" + "nome":"Turma Neil Tyson", + "data_inicio":"2021-05-01", + "data_final":"2022-11-01", + "modulo": 0 } ### @@ -34,4 +33,14 @@ Content-Type: application/json "data_nasc":"1999-04-15", "turma_id": 3, "nomeEspecialidades":"backend" +} + +### +PUT http://localhost:3003/update/class +Content-Type: application/json + +{ + "tableName": "Estudantes", + "peapleClassId": 1, + "peapleNewClassId": 2 } \ No newline at end of file diff --git a/src/GlobalFunctions/updateClass.ts b/src/GlobalFunctions/updateClass.ts new file mode 100644 index 0000000..5fa1f96 --- /dev/null +++ b/src/GlobalFunctions/updateClass.ts @@ -0,0 +1,10 @@ +import {connection} from '../connection' + +const updateClassStudant = async (classId: number, newClassId: number, tableName: string) =>{ + await connection.raw(` + UPDATE ${tableName} + SET turma_id = ${newClassId} + WHERE turma_id = ${classId}; + `) +} +export default updateClassStudant; \ No newline at end of file diff --git a/src/TypesAndEnums/Enums.ts b/src/TypesAndEnums/Enums.ts index 94e610c..445ea12 100644 --- a/src/TypesAndEnums/Enums.ts +++ b/src/TypesAndEnums/Enums.ts @@ -8,4 +8,9 @@ export enum Especialidades{ PROGRAMACAO_ORIENTADA_OBJETOS="programacao orientada objetos", BACKEND="backend" +} + +export enum Type{ + DOCENTE = "Docentes", + ESTUDANTE = "Estudantes" } \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts index 0583c53..4a2b961 100644 --- a/src/TypesAndEnums/Types.ts +++ b/src/TypesAndEnums/Types.ts @@ -1,4 +1,4 @@ -import { Especialidades } from './Enums' +import { Especialidades, Type } from './Enums' export type Docentes = { nome:string, @@ -6,4 +6,10 @@ export type Docentes = { data_nasc:string, turma_id:number, especialidade:Especialidades +} + +export type updateClass = { + tableName: Type, + peapleClassId: number, + peapleNewClassId: number } \ No newline at end of file diff --git a/src/endpoints/post/createClass.ts b/src/endpoints/class/post/createClass.ts similarity index 93% rename from src/endpoints/post/createClass.ts rename to src/endpoints/class/post/createClass.ts index a505620..5b97037 100644 --- a/src/endpoints/post/createClass.ts +++ b/src/endpoints/class/post/createClass.ts @@ -1,4 +1,4 @@ -import { connection } from '../../connection' +import { connection } from '../../../connection' import { Request, Response } from 'express' diff --git a/src/endpoints/post/post.ts b/src/endpoints/post/post.ts deleted file mode 100644 index 80a848f..0000000 --- a/src/endpoints/post/post.ts +++ /dev/null @@ -1 +0,0 @@ -//criar endpoint post \ No newline at end of file diff --git a/src/endpoints/delete/delete.ts b/src/endpoints/studant/delete/delete.ts similarity index 100% rename from src/endpoints/delete/delete.ts rename to src/endpoints/studant/delete/delete.ts diff --git a/src/endpoints/get/get.ts b/src/endpoints/studant/get/get.ts similarity index 100% rename from src/endpoints/get/get.ts rename to src/endpoints/studant/get/get.ts diff --git a/src/endpoints/post/createStudant.ts b/src/endpoints/studant/post/createStudant.ts similarity index 84% rename from src/endpoints/post/createStudant.ts rename to src/endpoints/studant/post/createStudant.ts index 451c8ac..9706431 100644 --- a/src/endpoints/post/createStudant.ts +++ b/src/endpoints/studant/post/createStudant.ts @@ -1,4 +1,4 @@ -import { connection } from '../../connection' +import { connection } from '../../../connection' import { Request, Response } from 'express' const createStudant = async ( @@ -13,12 +13,12 @@ const createStudant = async ( "${req.body.nome}", "${req.body.email}", "${req.body.data_nasc}", - "${req.body.turma_id}" + ${req.body.turma_id} )`) await connection.raw( ` - INSERT INTO Passatempo(nome) + INSERT INTO Passatempo (nome) VALUES( "${req.body.nomePassatempo}" ) diff --git a/src/endpoints/put/put.ts b/src/endpoints/studant/put/put.ts similarity index 100% rename from src/endpoints/put/put.ts rename to src/endpoints/studant/put/put.ts diff --git a/src/endpoints/post/createTeacher.ts b/src/endpoints/teacher/post/createTeacher.ts similarity index 94% rename from src/endpoints/post/createTeacher.ts rename to src/endpoints/teacher/post/createTeacher.ts index 199bde9..95f1e55 100644 --- a/src/endpoints/post/createTeacher.ts +++ b/src/endpoints/teacher/post/createTeacher.ts @@ -1,7 +1,7 @@ -import { connection } from '../../connection' +import { connection } from '../../../connection' import { Request, Response } from 'express' -import { Especialidades } from '../../TypesAndEnums/Enums' -import { Docentes } from '../../TypesAndEnums/Types' +import { Especialidades } from '../../../TypesAndEnums/Enums' +import { Docentes } from '../../../TypesAndEnums/Types' const createTeacher = async ( req: Request, diff --git a/src/endpoints/teacher/put/changeClass.ts b/src/endpoints/teacher/put/changeClass.ts new file mode 100644 index 0000000..f0d4aa4 --- /dev/null +++ b/src/endpoints/teacher/put/changeClass.ts @@ -0,0 +1,37 @@ +import { Request, Response } from 'express'; +import updateClassStudant from '../../../GlobalFunctions/updateClass'; +import { updateClass } from '../../../TypesAndEnums/Types' + +const changeClass = async (req: Request, + res: Response) => { + try { + let errorCode: number = 400 + const body: updateClass = { + tableName: req.body.tableName, + peapleClassId: Number(req.body.peapleClassId), + peapleNewClassId: Number(req.body.peapleNewClassId) + } + + if(body.tableName !== 'Docentes' && body.tableName !== 'Estudantes'){ + errorCode = 422 + throw new Error('tableName dont exist.') + } else if (!body.peapleClassId) { + errorCode = 422 + throw new Error('Invalid peapleClassId parameter.') + } else if (!body.peapleNewClassId) { + errorCode = 422 + throw new Error('Invalid peapleNewClassId parameter.') + } else if (!body.tableName) { + errorCode = 422 + throw new Error('Invalid talbleName parameter.') + } else { + await updateClassStudant(body.peapleClassId, body.peapleNewClassId, body.tableName) + res.status(200).end(`${body.tableName} updated successfully`) + } + + } catch (error) { + console.log(error) + res.status(400).send({ message: error.message }) + } +} +export default changeClass; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2362d5e..15e32c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import app from './app' -import createClass from './endpoints/post/createClass' -import createStudant from './endpoints/post/createStudant' -import createTeacher from './endpoints/post/createTeacher' +import createClass from './endpoints/class/post/createClass' +import createStudant from './endpoints/studant/post/createStudant' +import createTeacher from './endpoints/teacher/post/createTeacher' +import changeClass from './endpoints/teacher/put/changeClass' app.post ('/class/create', createClass) app.post('/studant/create', createStudant) app.post ('/teacher/create', createTeacher) +app.put('/update/class', changeClass) From de37a0d5ceb1aef58324eb99f1bb11260734b918 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Thu, 1 Apr 2021 19:02:08 +0100 Subject: [PATCH 04/22] =?UTF-8?q?Feito=20refatoramento=20nos=20c=C3=B3digo?= =?UTF-8?q?s=20das=20funcionalidades=20existentes=20at=C3=A9=20agora.=20Ta?= =?UTF-8?q?mb=C3=A9m=20criei=20um=20script=20que=20roda=20uma=20fun=C3=A7?= =?UTF-8?q?=C3=A3o=20que=20cria=20as=20tabelas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + request.rest | 34 ++++---- src/GlobalFunctions/globalFunction | 1 - src/GlobalFunctions/updateClass.ts | 6 +- src/TypesAndEnums/Enums.ts | 4 +- src/TypesAndEnums/Types.ts | 4 +- src/createTables/createTables.ts | 43 +++++++++++ src/endpoints/class/post/createClass.ts | 31 ++++++-- .../{teacher => class}/put/changeClass.ts | 8 +- src/endpoints/studant/post/createStudant.ts | 28 +++---- src/endpoints/teacher/post/createTeacher.ts | 77 +++---------------- src/index.ts | 4 +- 12 files changed, 121 insertions(+), 120 deletions(-) delete mode 100644 src/GlobalFunctions/globalFunction create mode 100644 src/createTables/createTables.ts rename src/endpoints/{teacher => class}/put/changeClass.ts (84%) diff --git a/package.json b/package.json index bf857ab..4c85446 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", "main": "index.js", "scripts": { + "run-tables": "clear && tsc node ./src/createTables/createTable.ts", "dev": "clear && ts-node-dev ./src/index.ts", "start": "clear && tsc && node ./build/index.js" }, diff --git a/request.rest b/request.rest index 88ed1ac..70da0c9 100644 --- a/request.rest +++ b/request.rest @@ -1,15 +1,14 @@ GET http://localhost:3003 ### -POST http://localhost:3003/studant/create +POST http://localhost:3003/student/create Content-Type: application/json { - "nome":"Daniel Sacramento", - "email":"daniel@gmail.com", - "data_nasc":"2000-04-15", - "turma_id": 1, - "nomePassatempo":"codar nas madrugadas portuguesas" + "name":"Ju", + "email":"juliene@gmail.com", + "birthdate":"2000-04-15", + "hobbies": "Dormir." } #### @@ -17,10 +16,10 @@ POST http://localhost:3003/class/create Content-Type: application/json { - "nome":"Turma Neil Tyson", - "data_inicio":"2021-05-01", - "data_final":"2022-11-01", - "modulo": 0 + "name":"Turma Ana da Hora", + "start_date":"2021-07-01", + "end_date":"2022-01-01", + "type_class": "Integral" } ### @@ -28,11 +27,10 @@ POST http://localhost:3003/teacher/create Content-Type: application/json { - "nome":"João", - "email":"joao@gmail.com", - "data_nasc":"1999-04-15", - "turma_id": 3, - "nomeEspecialidades":"backend" + "name":"Caio", + "email":"caio@gmail.com", + "birthdate":"1990-04-15", + "speciality": "Redux" } ### @@ -40,7 +38,7 @@ PUT http://localhost:3003/update/class Content-Type: application/json { - "tableName": "Estudantes", - "peapleClassId": 1, - "peapleNewClassId": 2 + "tableName": "Teachers", + "peapleClassId": "1617296352730", + "peapleNewClassId": "1617299457911" } \ No newline at end of file diff --git a/src/GlobalFunctions/globalFunction b/src/GlobalFunctions/globalFunction deleted file mode 100644 index 27f95d9..0000000 --- a/src/GlobalFunctions/globalFunction +++ /dev/null @@ -1 +0,0 @@ -//funções do projeto! \ No newline at end of file diff --git a/src/GlobalFunctions/updateClass.ts b/src/GlobalFunctions/updateClass.ts index 5fa1f96..5735e25 100644 --- a/src/GlobalFunctions/updateClass.ts +++ b/src/GlobalFunctions/updateClass.ts @@ -1,10 +1,10 @@ import {connection} from '../connection' -const updateClassStudant = async (classId: number, newClassId: number, tableName: string) =>{ +const updateClassStudant = async (classId: string, newClassId: string, tableName: string) =>{ await connection.raw(` UPDATE ${tableName} - SET turma_id = ${newClassId} - WHERE turma_id = ${classId}; + SET class_id = "${newClassId}" + WHERE id = "${classId}"; `) } export default updateClassStudant; \ No newline at end of file diff --git a/src/TypesAndEnums/Enums.ts b/src/TypesAndEnums/Enums.ts index 445ea12..e71f58c 100644 --- a/src/TypesAndEnums/Enums.ts +++ b/src/TypesAndEnums/Enums.ts @@ -11,6 +11,6 @@ export enum Especialidades{ } export enum Type{ - DOCENTE = "Docentes", - ESTUDANTE = "Estudantes" + TEACHER = "Teachers", + STUDENT = "Students" } \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts index 4a2b961..67e2537 100644 --- a/src/TypesAndEnums/Types.ts +++ b/src/TypesAndEnums/Types.ts @@ -10,6 +10,6 @@ export type Docentes = { export type updateClass = { tableName: Type, - peapleClassId: number, - peapleNewClassId: number + peapleClassId: string, + peapleNewClassId: string } \ No newline at end of file diff --git a/src/createTables/createTables.ts b/src/createTables/createTables.ts new file mode 100644 index 0000000..43b72cd --- /dev/null +++ b/src/createTables/createTables.ts @@ -0,0 +1,43 @@ +import {connection } from '../connection' + +const createTables = async () =>{ + try { + await connection.raw(` + CREATE TABLE Class ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + start_date DATE NOT NULL, + end_date DATE NOT NULL, + module ENUM ('1', '2', '3', '4', '5', '6', '7,', '0') DEFAULT '0', + type_class ENUM ("Integral", "Noturna") + ); + `) + + await connection.raw(` + CREATE TABLE Studants ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + hobbies VARCHAR(225), + class_id INT NULL DEFAULT '0', + FOREIGN KEY (class_id) REFERENCES Class(id) + ); + `) + + await connection.raw(` + CREATE TABLE Teachers ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), + class_id INT NULL DEFAULT '0', + FOREIGN KEY (class_id) REFERENCES Class(id) + ); + `) + } catch (error) { + console.log(error) + } +} +createTables() \ No newline at end of file diff --git a/src/endpoints/class/post/createClass.ts b/src/endpoints/class/post/createClass.ts index 5b97037..1b0beab 100644 --- a/src/endpoints/class/post/createClass.ts +++ b/src/endpoints/class/post/createClass.ts @@ -7,20 +7,35 @@ const createClass = async ( res: Response ): Promise => { try { + + let nameClass = req.body.name + if (req.body.type_class === 'Noturna') { + if (!req.body.name.includes('-na-night')) { + throw new Error('Nomes de turmas noturnas precisam terminar com -na-nigth.') + } else { + nameClass = req.body.name + } + } + await connection.raw( - `INSERT INTO Turmas (nome, data_inicio, data_final, modulo) + `INSERT INTO Class (id, name, start_date, end_date, type_class) VALUES( - "${req.body.nome}", - "${req.body.data_inicio}", - "${req.body.data_final}", - "${req.body.modulo}" - )` + "${Date.now()}", + "${nameClass}", + "${req.body.start_date}", + "${req.body.end_date}", + "${req.body.type_class}" + )` ) res.status(201).send('Turma criada com sucesso!') - + + } catch (error) { - res.status(500).send("Todos os campos devem ser preenchidos") + if (error.message.includes('type_class')) { + res.status(422).send('Este tipo de turma não existe.') + } + res.status(500).send(error.message) } } diff --git a/src/endpoints/teacher/put/changeClass.ts b/src/endpoints/class/put/changeClass.ts similarity index 84% rename from src/endpoints/teacher/put/changeClass.ts rename to src/endpoints/class/put/changeClass.ts index f0d4aa4..41f5314 100644 --- a/src/endpoints/teacher/put/changeClass.ts +++ b/src/endpoints/class/put/changeClass.ts @@ -8,11 +8,13 @@ const changeClass = async (req: Request, let errorCode: number = 400 const body: updateClass = { tableName: req.body.tableName, - peapleClassId: Number(req.body.peapleClassId), - peapleNewClassId: Number(req.body.peapleNewClassId) + peapleClassId: req.body.peapleClassId, + peapleNewClassId: req.body.peapleNewClassId } - if(body.tableName !== 'Docentes' && body.tableName !== 'Estudantes'){ + //verificar se estudante existe + + if(body.tableName !== 'Teachers' && body.tableName !== 'Students'){ errorCode = 422 throw new Error('tableName dont exist.') } else if (!body.peapleClassId) { diff --git a/src/endpoints/studant/post/createStudant.ts b/src/endpoints/studant/post/createStudant.ts index 9706431..4f6fc41 100644 --- a/src/endpoints/studant/post/createStudant.ts +++ b/src/endpoints/studant/post/createStudant.ts @@ -6,29 +6,29 @@ const createStudant = async ( res: Response ): Promise => { try { + + let classId = 0 + if(!req.body.class_id){ + classId = 1 + } else { + classId = Number(req.body.class_id) + } + await connection.raw( ` - INSERT INTO Estudantes (nome, email, data_nasc, turma_id) + INSERT INTO Students (id, name, email, birthdate, hobbies) VALUES( - "${req.body.nome}", + "${Date.now()}", + "${req.body.name}", "${req.body.email}", - "${req.body.data_nasc}", - ${req.body.turma_id} + "${req.body.birthdate}", + "${req.body.hobbies}" )`) - - await connection.raw( - ` - INSERT INTO Passatempo (nome) - VALUES( - "${req.body.nomePassatempo}" - ) - ` - ) res.status(201).send('Estudante criado com sucesso!') } catch (error) { - res.status(500).send("Todos os campos devem ser preenchidos") + res.status(500).send(error.message) } } diff --git a/src/endpoints/teacher/post/createTeacher.ts b/src/endpoints/teacher/post/createTeacher.ts index 95f1e55..561c9b9 100644 --- a/src/endpoints/teacher/post/createTeacher.ts +++ b/src/endpoints/teacher/post/createTeacher.ts @@ -8,82 +8,25 @@ const createTeacher = async ( res: Response ): Promise => { try { + await connection.raw( ` - INSERT INTO Docentes (nome, email, data_nasc, turma_id) + INSERT INTO Teachers (id, name, email, birthdate, speciality) VALUES( - "${req.body.nome}", + "${Date.now()}", + "${req.body.name}", "${req.body.email}", - "${req.body.data_nasc}", - "${req.body.turma_id}" + "${req.body.birthdate}", + "${req.body.speciality}" )`) - if(Especialidades.BACKEND === 'backend'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "Backend" - ) - ` - ) - } else if(Especialidades.CSS === 'css'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "CSS" - ) - `) - } else if (Especialidades.PROGRAMACAO_ORIENTADA_OBJETOS === 'programacao orientada objetos'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "Programacao orientada objetos" - ) - `) - } else if(Especialidades.REACT === 'react'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "React" - ) - `) - } else if(Especialidades.REDUX === 'redux'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "Redux" - ) - `) - } else if(Especialidades.TESTES === 'testes'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "Testes" - ) - `) - } else if(Especialidades.TYPESCRIPT === 'typescript'){ - await connection.raw( - ` - INSERT INTO Especialidade(nome) - VALUES( - "Typescript" - ) - `) - } else{ - throw new Error('Especialidade inválida: Especialidades suportadas: Backend, Css, Programacao Orientada Objeto, React, Redux, Testes, Typescript') - } - - res.status(201).send('Professor criado com sucesso!') } catch (error) { - res.status(500).send("Todos os campos devem ser preenchidos") + if(error.message.includes('speciality')){ + res.status(500).send('Esta especialidade não existe, tente novamente.') + } + res.status(500).send(error.message) } } diff --git a/src/index.ts b/src/index.ts index 15e32c6..286a912 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,9 @@ import app from './app' import createClass from './endpoints/class/post/createClass' import createStudant from './endpoints/studant/post/createStudant' import createTeacher from './endpoints/teacher/post/createTeacher' -import changeClass from './endpoints/teacher/put/changeClass' +import changeClass from './endpoints/class/put/changeClass' app.post ('/class/create', createClass) -app.post('/studant/create', createStudant) +app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) app.put('/update/class', changeClass) From e5912d1488bee08d247204f93831062b40b6173f Mon Sep 17 00:00:00 2001 From: Bruno-Galhardi Date: Thu, 1 Apr 2021 16:28:37 -0300 Subject: [PATCH 05/22] feito o primeiro desafio, pegar nome dos estudantes por turma --- package.json | 2 +- request.rest | 33 ++++++++++--------- .../studant/get/getStudantsByClass.ts | 23 +++++++++++++ src/index.ts | 3 ++ 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 src/endpoints/studant/get/getStudantsByClass.ts diff --git a/package.json b/package.json index 4c85446..331ab9c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", "main": "index.js", "scripts": { - "run-tables": "clear && tsc node ./src/createTables/createTable.ts", + "run-tables": "tsc node ./build/createTables/createTable.js", "dev": "clear && ts-node-dev ./src/index.ts", "start": "clear && tsc && node ./build/index.js" }, diff --git a/request.rest b/request.rest index 70da0c9..20cc2ff 100644 --- a/request.rest +++ b/request.rest @@ -5,10 +5,10 @@ POST http://localhost:3003/student/create Content-Type: application/json { - "name":"Ju", - "email":"juliene@gmail.com", - "birthdate":"2000-04-15", - "hobbies": "Dormir." + "name":"Amigo do Daniel", + "email":"Amigodaniel@gmail.com", + "birthdate":"1953-07-21", + "hobbies": "Codar com o daniel e ver o cr7." } #### @@ -16,9 +16,9 @@ POST http://localhost:3003/class/create Content-Type: application/json { - "name":"Turma Ana da Hora", - "start_date":"2021-07-01", - "end_date":"2022-01-01", + "name":"Turma IPA", + "start_date":"2021-06-01", + "end_date":"2022-12-01", "type_class": "Integral" } @@ -27,10 +27,10 @@ POST http://localhost:3003/teacher/create Content-Type: application/json { - "name":"Caio", - "email":"caio@gmail.com", - "birthdate":"1990-04-15", - "speciality": "Redux" + "name":"João", + "email":"joao@gmail.com", + "birthdate":"1996-04-15", + "speciality": "Backend" } ### @@ -38,7 +38,10 @@ PUT http://localhost:3003/update/class Content-Type: application/json { - "tableName": "Teachers", - "peapleClassId": "1617296352730", - "peapleNewClassId": "1617299457911" -} \ No newline at end of file + "tableName": "Students", + "peapleClassId": "1617303114836", + "peapleNewClassId": "1617303186439" +} + +### +GET http://localhost:3003/students/1617303214106 \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudantsByClass.ts b/src/endpoints/studant/get/getStudantsByClass.ts new file mode 100644 index 0000000..3f49735 --- /dev/null +++ b/src/endpoints/studant/get/getStudantsByClass.ts @@ -0,0 +1,23 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' + + const getStudantsByClass = async (req:Request, res:Response): Promise => { + + try { + const result = await connection.raw(` + SELECT Students.name + FROM Students + JOIN Class + ON Students.class_id = "${req.params.id}" + `); + + + res.status(200).send(result[0]) + + } + catch (error) { + res.status(500).send("Erro o encontrar os alunos dessa turma"); + } +}; + +export default getStudantsByClass \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 286a912..745b7b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,10 @@ import createClass from './endpoints/class/post/createClass' import createStudant from './endpoints/studant/post/createStudant' import createTeacher from './endpoints/teacher/post/createTeacher' import changeClass from './endpoints/class/put/changeClass' +import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' + +app.get('/students/:id', getStudantsByClass) app.post ('/class/create', createClass) app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) From 2fb9a1848d50c7b2bef64729d9b16ccdae91a293 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Thu, 1 Apr 2021 20:31:48 +0100 Subject: [PATCH 06/22] Resolvido bug no script de criar tabelas. --- package.json | 2 +- src/createTables/createTables.ts | 28 +++++++++++++++------------- tsconfig.json | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 4c85446..5fd5617 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", "main": "index.js", "scripts": { - "run-tables": "clear && tsc node ./src/createTables/createTable.ts", + "tables": "clear && tsc && node ./build/createTables/createTables.js", "dev": "clear && ts-node-dev ./src/index.ts", "start": "clear && tsc && node ./build/index.js" }, diff --git a/src/createTables/createTables.ts b/src/createTables/createTables.ts index 43b72cd..13f1bfa 100644 --- a/src/createTables/createTables.ts +++ b/src/createTables/createTables.ts @@ -1,43 +1,45 @@ -import {connection } from '../connection' +import { connection } from '../connection' -const createTables = async () =>{ +const createTables = async (): Promise => { try { await connection.raw(` CREATE TABLE Class ( - id INT PRIMARY KEY AUTO_INCREMENT, + id VARCHAR(255) PRIMARY KEY, name VARCHAR(50) NOT NULL, start_date DATE NOT NULL, end_date DATE NOT NULL, - module ENUM ('1', '2', '3', '4', '5', '6', '7,', '0') DEFAULT '0', + module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT '0', type_class ENUM ("Integral", "Noturna") ); `) await connection.raw(` - CREATE TABLE Studants ( - id INT PRIMARY KEY AUTO_INCREMENT, + CREATE TABLE IF NOT EXISTS Teachers ( + id VARCHAR(255) PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL UNIQUE, birthdate DATE NOT NULL, - hobbies VARCHAR(225), - class_id INT NULL DEFAULT '0', + speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), + class_id VARCHAR(255) NULL, FOREIGN KEY (class_id) REFERENCES Class(id) ); `) await connection.raw(` - CREATE TABLE Teachers ( - id INT PRIMARY KEY AUTO_INCREMENT, + CREATE TABLE Students ( + id VARCHAR(255) PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL UNIQUE, birthdate DATE NOT NULL, - speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), - class_id INT NULL DEFAULT '0', + hobbies VARCHAR(225), + class_id VARCHAR(255) NULL, FOREIGN KEY (class_id) REFERENCES Class(id) ); `) + console.log('Funfou') + connection.destroy(); } catch (error) { - console.log(error) + throw new Error(error.message || error.sqlMessage); } } createTables() \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e124967..3911e42 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ + "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ From 0560940e320530f4317981b455d6f166b754ee9b Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Fri, 2 Apr 2021 00:30:11 +0100 Subject: [PATCH 07/22] Implementado funcionalidade de pegar idade. --- request.rest | 5 +++- src/GlobalFunctions/aboutDate/addZero.ts | 8 ++++++ src/GlobalFunctions/aboutDate/convertDate.ts | 11 ++++++++ .../aboutDate/convertDateToTimestamp.ts | 9 ++++++ src/GlobalFunctions/aboutDate/currentDate.ts | 9 ++++++ src/GlobalFunctions/aboutDate/getAge.ts | 28 +++++++++++++++++++ .../aboutDate/timestampToYear.ts | 7 +++++ src/endpoints/studant/get/get.ts | 1 - src/endpoints/studant/get/getStudentAge.ts | 17 +++++++++++ src/index.ts | 3 +- 10 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/GlobalFunctions/aboutDate/addZero.ts create mode 100644 src/GlobalFunctions/aboutDate/convertDate.ts create mode 100644 src/GlobalFunctions/aboutDate/convertDateToTimestamp.ts create mode 100644 src/GlobalFunctions/aboutDate/currentDate.ts create mode 100644 src/GlobalFunctions/aboutDate/getAge.ts create mode 100644 src/GlobalFunctions/aboutDate/timestampToYear.ts delete mode 100644 src/endpoints/studant/get/get.ts create mode 100644 src/endpoints/studant/get/getStudentAge.ts diff --git a/request.rest b/request.rest index 20cc2ff..fedb184 100644 --- a/request.rest +++ b/request.rest @@ -44,4 +44,7 @@ Content-Type: application/json } ### -GET http://localhost:3003/students/1617303214106 \ No newline at end of file +GET http://localhost:3003/students/1617312546437 + +### +GET http://localhost:3003/age/student/1617312546437 \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/addZero.ts b/src/GlobalFunctions/aboutDate/addZero.ts new file mode 100644 index 0000000..73c13ca --- /dev/null +++ b/src/GlobalFunctions/aboutDate/addZero.ts @@ -0,0 +1,8 @@ +// adiciona 0 nos dates e nos months quando eles estão na casa de unidade. + +export const addZero = (numero: number) => { + if (numero <= 9) + return "0" + numero; + else + return numero; +} diff --git a/src/GlobalFunctions/aboutDate/convertDate.ts b/src/GlobalFunctions/aboutDate/convertDate.ts new file mode 100644 index 0000000..e170edd --- /dev/null +++ b/src/GlobalFunctions/aboutDate/convertDate.ts @@ -0,0 +1,11 @@ +import { addZero } from './addZero' + +// formata data para dd/mm/yyyy + +export const convertDate = (valueDate: string) => { + let data = new Date(valueDate.toString()); + let dataFormatada = (addZero((data.getDate()))) + "/" + + (addZero((data.getMonth() + 1))) + "/" + + data.getFullYear(); + return dataFormatada +} \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/convertDateToTimestamp.ts b/src/GlobalFunctions/aboutDate/convertDateToTimestamp.ts new file mode 100644 index 0000000..c301831 --- /dev/null +++ b/src/GlobalFunctions/aboutDate/convertDateToTimestamp.ts @@ -0,0 +1,9 @@ +// converte datas para timestamp + +export const convertDateToTimestamp = (date: string) => { + const myDate = date + const newMyDate = myDate.split("/") + const newDate = new Date(Number(newMyDate[2]), (Number(newMyDate[1]) -1), Number(newMyDate[0])) + + return newDate.getTime() +} \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/currentDate.ts b/src/GlobalFunctions/aboutDate/currentDate.ts new file mode 100644 index 0000000..3d07bae --- /dev/null +++ b/src/GlobalFunctions/aboutDate/currentDate.ts @@ -0,0 +1,9 @@ +import {convertDate} from './convertDate' + +// pegando a data atual + +export const currentDate = () =>{ + const date = new Date + const newDate = convertDate(String(date)) + return newDate +} \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/getAge.ts b/src/GlobalFunctions/aboutDate/getAge.ts new file mode 100644 index 0000000..c654eda --- /dev/null +++ b/src/GlobalFunctions/aboutDate/getAge.ts @@ -0,0 +1,28 @@ +import { connection } from '../../connection' +import { convertDate } from './convertDate' +import { convertDateToTimestamp } from './convertDateToTimestamp' +import { currentDate } from './currentDate' +import { timestampToYear } from './timestampToYear' + +// pegando idade da pessoa + +export const getAge = async (idUser: string) => { + const birthdate = await connection.raw(` + SELECT birthdate + FROM Students + WHERE id = "${idUser}" + `) + + const dateNow = currentDate() + const dataFormatada = convertDate(birthdate[0][0].birthdate) + + const timestampNow = convertDateToTimestamp(dateNow) + const timestampAgePeople = convertDateToTimestamp(dataFormatada) + + const dateMilisecunds = timestampNow - timestampAgePeople + const ageInYears = timestampToYear(dateMilisecunds) + + + return Math.floor(ageInYears) +} +export default getAge; \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/timestampToYear.ts b/src/GlobalFunctions/aboutDate/timestampToYear.ts new file mode 100644 index 0000000..fad93cf --- /dev/null +++ b/src/GlobalFunctions/aboutDate/timestampToYear.ts @@ -0,0 +1,7 @@ +// convertendo timestamp para ano + +export const timestampToYear = (timestamp: number) =>{ + const ageinYears = timestamp / 1000 / 60 / 60 / 24 / 365 + + return ageinYears +} \ No newline at end of file diff --git a/src/endpoints/studant/get/get.ts b/src/endpoints/studant/get/get.ts deleted file mode 100644 index d13a26f..0000000 --- a/src/endpoints/studant/get/get.ts +++ /dev/null @@ -1 +0,0 @@ -//criar endpoint de get \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudentAge.ts b/src/endpoints/studant/get/getStudentAge.ts new file mode 100644 index 0000000..c451868 --- /dev/null +++ b/src/endpoints/studant/get/getStudentAge.ts @@ -0,0 +1,17 @@ +import { Request, Response } from 'express' +import getAge from "../../../GlobalFunctions/aboutDate/getAge"; + +const getStudentAge = async (req: Request, res: Response): Promise => { + + try { + const age: number = await getAge(req.params.id) + + res.status(200).send({Age: age}) + + } + catch (error) { + res.status(500).send(error.message); + } +}; + +export default getStudentAge; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 745b7b6..883f4b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,9 @@ import createStudant from './endpoints/studant/post/createStudant' import createTeacher from './endpoints/teacher/post/createTeacher' import changeClass from './endpoints/class/put/changeClass' import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' +import getStudentAge from './endpoints/studant/get/getStudentAge' - +app.get('/age/student/:id', getStudentAge) app.get('/students/:id', getStudantsByClass) app.post ('/class/create', createClass) app.post('/student/create', createStudant) From 21daaa35ff1f253d752b76a4c5f6f7550a59ff5b Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 15:29:34 +0100 Subject: [PATCH 08/22] Refatorado funcionalidade de pegar idade, para funcionar tanto para alunos quanto para professores. --- request.rest | 2 +- src/GlobalFunctions/aboutDate/getAge.ts | 4 ++-- src/GlobalFunctions/capitalize/capitalize.ts | 4 ++++ src/TypesAndEnums/Types.ts | 5 ++++ src/endpoints/both/getAge.ts | 24 ++++++++++++++++++++ src/endpoints/studant/get/getStudentAge.ts | 17 -------------- src/index.ts | 4 ++-- 7 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/GlobalFunctions/capitalize/capitalize.ts create mode 100644 src/endpoints/both/getAge.ts delete mode 100644 src/endpoints/studant/get/getStudentAge.ts diff --git a/request.rest b/request.rest index fedb184..665cd4d 100644 --- a/request.rest +++ b/request.rest @@ -47,4 +47,4 @@ Content-Type: application/json GET http://localhost:3003/students/1617312546437 ### -GET http://localhost:3003/age/student/1617312546437 \ No newline at end of file +GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers \ No newline at end of file diff --git a/src/GlobalFunctions/aboutDate/getAge.ts b/src/GlobalFunctions/aboutDate/getAge.ts index c654eda..89c8a36 100644 --- a/src/GlobalFunctions/aboutDate/getAge.ts +++ b/src/GlobalFunctions/aboutDate/getAge.ts @@ -6,10 +6,10 @@ import { timestampToYear } from './timestampToYear' // pegando idade da pessoa -export const getAge = async (idUser: string) => { +export const getAge = async (idUser: string, tableName: string) => { const birthdate = await connection.raw(` SELECT birthdate - FROM Students + FROM ${tableName} WHERE id = "${idUser}" `) diff --git a/src/GlobalFunctions/capitalize/capitalize.ts b/src/GlobalFunctions/capitalize/capitalize.ts new file mode 100644 index 0000000..e67e5d1 --- /dev/null +++ b/src/GlobalFunctions/capitalize/capitalize.ts @@ -0,0 +1,4 @@ +export const capitalize = (string: string) => { + if (typeof string !== 'string') return '' + return string.charAt(0).toUpperCase() + string.slice(1) + } \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts index 67e2537..8871780 100644 --- a/src/TypesAndEnums/Types.ts +++ b/src/TypesAndEnums/Types.ts @@ -12,4 +12,9 @@ export type updateClass = { tableName: Type, peapleClassId: string, peapleNewClassId: string +} + +export type data = { + id: string, + tableName: string } \ No newline at end of file diff --git a/src/endpoints/both/getAge.ts b/src/endpoints/both/getAge.ts new file mode 100644 index 0000000..bd8da01 --- /dev/null +++ b/src/endpoints/both/getAge.ts @@ -0,0 +1,24 @@ +import { Request, Response } from 'express' +import getAge from "../../GlobalFunctions/aboutDate/getAge"; +import { capitalize } from '../../GlobalFunctions/capitalize/capitalize'; +import { data } from '../../TypesAndEnums/Types'; + +const getStudentAge = async (req: Request, res: Response): Promise => { + + try { + const data: data = { + id: req.query.id as string, + tableName: capitalize(req.query.tableName as string) + } + + const age: number = await getAge(data.id, data.tableName) + + res.status(200).send({ Age: age }) + + } + catch (error) { + res.status(500).send(error.message); + } +}; + +export default getStudentAge; \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudentAge.ts b/src/endpoints/studant/get/getStudentAge.ts deleted file mode 100644 index c451868..0000000 --- a/src/endpoints/studant/get/getStudentAge.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Request, Response } from 'express' -import getAge from "../../../GlobalFunctions/aboutDate/getAge"; - -const getStudentAge = async (req: Request, res: Response): Promise => { - - try { - const age: number = await getAge(req.params.id) - - res.status(200).send({Age: age}) - - } - catch (error) { - res.status(500).send(error.message); - } -}; - -export default getStudentAge; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 883f4b3..d4e6aec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,9 +4,9 @@ import createStudant from './endpoints/studant/post/createStudant' import createTeacher from './endpoints/teacher/post/createTeacher' import changeClass from './endpoints/class/put/changeClass' import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' -import getStudentAge from './endpoints/studant/get/getStudentAge' +import getStudentAge from './endpoints/both/getAge' -app.get('/age/student/:id', getStudentAge) +app.get('/search/age', getStudentAge) app.get('/students/:id', getStudantsByClass) app.post ('/class/create', createClass) app.post('/student/create', createStudant) From 95c4295b022477d27ff89907c92742fe513768ae Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 17:14:26 +0100 Subject: [PATCH 09/22] Refatorado funcionalidade de pegar estudantes por turma. --- request.rest | 2 +- src/TypesAndEnums/Types.ts | 8 ++++ .../studant/get/getStudantsByClass.ts | 46 +++++++++++++------ src/endpoints/studant/post/createStudant.ts | 2 +- src/endpoints/teacher/post/createTeacher.ts | 2 +- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/request.rest b/request.rest index 665cd4d..a2414d8 100644 --- a/request.rest +++ b/request.rest @@ -44,7 +44,7 @@ Content-Type: application/json } ### -GET http://localhost:3003/students/1617312546437 +GET http://localhost:3003/students/1617547014022 ### GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts index 8871780..39db047 100644 --- a/src/TypesAndEnums/Types.ts +++ b/src/TypesAndEnums/Types.ts @@ -17,4 +17,12 @@ export type updateClass = { export type data = { id: string, tableName: string +} + +export type student = { + id: string, + student_name: string, + email: string, + hobbies: string, + birthdate: string } \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudantsByClass.ts b/src/endpoints/studant/get/getStudantsByClass.ts index 3f49735..824f72e 100644 --- a/src/endpoints/studant/get/getStudantsByClass.ts +++ b/src/endpoints/studant/get/getStudantsByClass.ts @@ -1,23 +1,43 @@ import { connection } from "../../../connection"; import { Request, Response } from 'express' +import { convertDate } from "../../../GlobalFunctions/aboutDate/convertDate"; +import { student } from "../../../TypesAndEnums/Types"; - const getStudantsByClass = async (req:Request, res:Response): Promise => { +const getClassStudants = async (req: Request, res: Response): Promise => { try { - const result = await connection.raw(` - SELECT Students.name - FROM Students - JOIN Class - ON Students.class_id = "${req.params.id}" - `); + const QueryResult = await connection.raw(` + SELECT + C.class_name, + S.id, + S.student_name, + S.email, + S.birthdate, + S.hobbies + FROM Students S + JOIN Class C + ON S.class_id = "${req.params.id}" + `) - - res.status(200).send(result[0]) + const students = QueryResult[0].map((student: student) => { + return ({ + id: student.id, + student_name: student.student_name, + email: student.email, + hobbies: student.hobbies, + birthdate: convertDate(student.birthdate) + }) + }) - } + res.status(200).send({ + className: QueryResult[0][0].class_name, + student: students + }) + + } catch (error) { - res.status(500).send("Erro o encontrar os alunos dessa turma"); + res.status(500).send(error.message) } -}; +} -export default getStudantsByClass \ No newline at end of file +export default getClassStudants \ No newline at end of file diff --git a/src/endpoints/studant/post/createStudant.ts b/src/endpoints/studant/post/createStudant.ts index 4f6fc41..5f00149 100644 --- a/src/endpoints/studant/post/createStudant.ts +++ b/src/endpoints/studant/post/createStudant.ts @@ -16,7 +16,7 @@ const createStudant = async ( await connection.raw( ` - INSERT INTO Students (id, name, email, birthdate, hobbies) + INSERT INTO Students (id, student_name, email, birthdate, hobbies) VALUES( "${Date.now()}", "${req.body.name}", diff --git a/src/endpoints/teacher/post/createTeacher.ts b/src/endpoints/teacher/post/createTeacher.ts index 561c9b9..17e616d 100644 --- a/src/endpoints/teacher/post/createTeacher.ts +++ b/src/endpoints/teacher/post/createTeacher.ts @@ -11,7 +11,7 @@ const createTeacher = async ( await connection.raw( ` - INSERT INTO Teachers (id, name, email, birthdate, speciality) + INSERT INTO Teachers (id, teacher_name, email, birthdate, speciality) VALUES( "${Date.now()}", "${req.body.name}", From ff0a67967985bb4ee9e5232f100b3cbd95627afd Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 18:11:35 +0100 Subject: [PATCH 10/22] Implementado funcionalidade de pegar professor pela classe. --- request.rest | 11 +++-- src/GlobalFunctions/error/notFound.ts | 3 ++ src/TypesAndEnums/Types.ts | 8 ++++ .../teacher/get/getTeacherByClass.ts | 46 +++++++++++++++++++ src/index.ts | 2 + 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/GlobalFunctions/error/notFound.ts create mode 100644 src/endpoints/teacher/get/getTeacherByClass.ts diff --git a/request.rest b/request.rest index a2414d8..73adf63 100644 --- a/request.rest +++ b/request.rest @@ -38,13 +38,16 @@ PUT http://localhost:3003/update/class Content-Type: application/json { - "tableName": "Students", - "peapleClassId": "1617303114836", - "peapleNewClassId": "1617303186439" + "tableName": "Teachers", + "peapleClassId": "1617546212494", + "peapleNewClassId": "1617547014022" } ### GET http://localhost:3003/students/1617547014022 ### -GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers \ No newline at end of file +GET http://localhost:3003/teachers/1617547014022 + +### +GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers diff --git a/src/GlobalFunctions/error/notFound.ts b/src/GlobalFunctions/error/notFound.ts new file mode 100644 index 0000000..9eda0a0 --- /dev/null +++ b/src/GlobalFunctions/error/notFound.ts @@ -0,0 +1,3 @@ +export const notFound = (value: string[]) =>{ + if(value.length === 0) throw new Error('No teacher found') +} \ No newline at end of file diff --git a/src/TypesAndEnums/Types.ts b/src/TypesAndEnums/Types.ts index 39db047..6901cef 100644 --- a/src/TypesAndEnums/Types.ts +++ b/src/TypesAndEnums/Types.ts @@ -25,4 +25,12 @@ export type student = { email: string, hobbies: string, birthdate: string +} + +export type teacher = { + id: string, + teachers_name: string, + email: string, + speciality: string, + birthdate: string } \ No newline at end of file diff --git a/src/endpoints/teacher/get/getTeacherByClass.ts b/src/endpoints/teacher/get/getTeacherByClass.ts new file mode 100644 index 0000000..4bd4676 --- /dev/null +++ b/src/endpoints/teacher/get/getTeacherByClass.ts @@ -0,0 +1,46 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' +import { convertDate } from "../../../GlobalFunctions/aboutDate/convertDate"; +import { teacher } from "../../../TypesAndEnums/Types"; +import { notFound } from "../../../GlobalFunctions/error/notFound"; + +const getTeacherByClass = async (req: Request, res: Response): Promise => { + + try { + const QueryResult = await connection.raw(` + SELECT + C.class_name, + T.id, + T.teachers_name, + T.email, + T.birthdate, + T.speciality + FROM Teachers T + JOIN Class C + ON T.class_id = "${req.params.id}" + `) + + const teachers = QueryResult[0].map((teacher: teacher) => { + return ({ + id: teacher.id, + teachers_name: teacher.teachers_name, + email: teacher.email, + speciality: teacher.speciality, + birthdate: convertDate(teacher.birthdate) + }) + }) + + notFound(teachers) + + res.status(200).send({ + className: QueryResult[0][0].class_name, + teachers: teachers + }) + + } + catch (error) { + res.status(500).send(error.message) + } +} + +export default getTeacherByClass \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d4e6aec..2ec572b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,11 @@ import createTeacher from './endpoints/teacher/post/createTeacher' import changeClass from './endpoints/class/put/changeClass' import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' import getStudentAge from './endpoints/both/getAge' +import getTeacherByClass from './endpoints/teacher/get/getTeacherByClass' app.get('/search/age', getStudentAge) app.get('/students/:id', getStudantsByClass) +app.get('/teachers/:id', getTeacherByClass) app.post ('/class/create', createClass) app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) From 031a85e12c960125ef45cff8d76716231e2e1355 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 22:48:22 +0100 Subject: [PATCH 11/22] Implementado funcionalidade de pegar alunos por hobby. --- request.rest | 13 ++++--- .../studant/get/getStudantsByClass.ts | 4 +- .../studant/get/getStudentsByHobbies.ts | 39 +++++++++++++++++++ src/index.ts | 2 + 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 src/endpoints/studant/get/getStudentsByHobbies.ts diff --git a/request.rest b/request.rest index 73adf63..ca891d0 100644 --- a/request.rest +++ b/request.rest @@ -1,14 +1,12 @@ -GET http://localhost:3003 - ### POST http://localhost:3003/student/create Content-Type: application/json { - "name":"Amigo do Daniel", - "email":"Amigodaniel@gmail.com", - "birthdate":"1953-07-21", - "hobbies": "Codar com o daniel e ver o cr7." + "name":"Daniel", + "email":"daniel@gmail.com", + "birthdate":"1993-05-19", + "hobbies": "Patinar." } #### @@ -51,3 +49,6 @@ GET http://localhost:3003/teachers/1617547014022 ### GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers + +### +GET http://localhost:3003/students/hobbies \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudantsByClass.ts b/src/endpoints/studant/get/getStudantsByClass.ts index 824f72e..02e7110 100644 --- a/src/endpoints/studant/get/getStudantsByClass.ts +++ b/src/endpoints/studant/get/getStudantsByClass.ts @@ -3,7 +3,7 @@ import { Request, Response } from 'express' import { convertDate } from "../../../GlobalFunctions/aboutDate/convertDate"; import { student } from "../../../TypesAndEnums/Types"; -const getClassStudants = async (req: Request, res: Response): Promise => { +const getStudantsByClass = async (req: Request, res: Response): Promise => { try { const QueryResult = await connection.raw(` @@ -40,4 +40,4 @@ const getClassStudants = async (req: Request, res: Response): Promise => { } } -export default getClassStudants \ No newline at end of file +export default getStudantsByClass \ No newline at end of file diff --git a/src/endpoints/studant/get/getStudentsByHobbies.ts b/src/endpoints/studant/get/getStudentsByHobbies.ts new file mode 100644 index 0000000..f1b68f1 --- /dev/null +++ b/src/endpoints/studant/get/getStudentsByHobbies.ts @@ -0,0 +1,39 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' +import { convertDate } from "../../../GlobalFunctions/aboutDate/convertDate"; +import { student } from "../../../TypesAndEnums/Types"; +import { notFound } from "../../../GlobalFunctions/error/notFound"; + +const getStudentsByHobbies = async (req: Request, res: Response): Promise => { + + try { + const QueryResult = await connection.raw(` + SELECT * FROM Students WHERE hobbies IN ( + SELECT hobbies FROM Students + GROUP BY hobbies HAVING COUNT(*) > 1 + ); + `) + + const students = QueryResult[0].map((student: student) => { + return ({ + id: student.id, + student_name: student.student_name, + email: student.email, + hobbies: student.hobbies, + birthdate: convertDate(student.birthdate) + }) + }) + + notFound(students) + + res.status(200).send({ + students: students + }) + + } + catch (error) { + res.status(500).send(error.message) + } +} + +export default getStudentsByHobbies \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2ec572b..da935d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,9 @@ import changeClass from './endpoints/class/put/changeClass' import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' import getStudentAge from './endpoints/both/getAge' import getTeacherByClass from './endpoints/teacher/get/getTeacherByClass' +import getStudentsByHobbies from './endpoints/studant/get/getStudentsByHobbies' +app.get('/students/hobbies', getStudentsByHobbies) app.get('/search/age', getStudentAge) app.get('/students/:id', getStudantsByClass) app.get('/teachers/:id', getTeacherByClass) From cf7357c153032f6b24803158feb57f3b1b53e6f9 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 23:37:24 +0100 Subject: [PATCH 12/22] Implementado funcionalidade de remover aluno de turma. --- request.rest | 5 +++- src/endpoints/studant/delete/delete.ts | 1 - .../studant/delete/removeStudentsFromClass.ts | 23 +++++++++++++++++++ src/index.ts | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) delete mode 100644 src/endpoints/studant/delete/delete.ts create mode 100644 src/endpoints/studant/delete/removeStudentsFromClass.ts diff --git a/request.rest b/request.rest index ca891d0..9a9efb8 100644 --- a/request.rest +++ b/request.rest @@ -51,4 +51,7 @@ GET http://localhost:3003/teachers/1617547014022 GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers ### -GET http://localhost:3003/students/hobbies \ No newline at end of file +GET http://localhost:3003/students/hobbies + +### +PUT http://localhost:3003/student/remove-class/:id \ No newline at end of file diff --git a/src/endpoints/studant/delete/delete.ts b/src/endpoints/studant/delete/delete.ts deleted file mode 100644 index b9a57a1..0000000 --- a/src/endpoints/studant/delete/delete.ts +++ /dev/null @@ -1 +0,0 @@ -//criar endpoint de delete \ No newline at end of file diff --git a/src/endpoints/studant/delete/removeStudentsFromClass.ts b/src/endpoints/studant/delete/removeStudentsFromClass.ts new file mode 100644 index 0000000..ac0e0ba --- /dev/null +++ b/src/endpoints/studant/delete/removeStudentsFromClass.ts @@ -0,0 +1,23 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' + +const removeStudentFromClass = async (req: Request, res: Response): Promise => { + try { + const id = Number(req.params.id) + + if(isNaN(id) === true) throw new Error("Invalid Id.") + + await connection.raw(` + UPDATE Students + SET class_id = null + WHERE id = "${id}" + `) + + res.status(200).send('Student removed successfully.') + + } catch (error) { + console.log(error.message) + res.status(400).send(error.message) + } +} +export default removeStudentFromClass \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index da935d2..ba1f452 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import getStudantsByClass from './endpoints/studant/get/getStudantsByClass' import getStudentAge from './endpoints/both/getAge' import getTeacherByClass from './endpoints/teacher/get/getTeacherByClass' import getStudentsByHobbies from './endpoints/studant/get/getStudentsByHobbies' +import removeStudentFromClass from './endpoints/studant/delete/removeStudentsFromClass' app.get('/students/hobbies', getStudentsByHobbies) app.get('/search/age', getStudentAge) @@ -16,3 +17,4 @@ app.post ('/class/create', createClass) app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) app.put('/update/class', changeClass) +app.put('/student/remove-class/:id', removeStudentFromClass) From 6b163f659303bccf6343775d810e3ce7b1bf909a Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 23:44:20 +0100 Subject: [PATCH 13/22] Implementado funcinalidade de remover estudante do curso. --- request.rest | 5 +++- src/endpoints/studant/delete/removeStudent.ts | 23 +++++++++++++++++++ src/index.ts | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/endpoints/studant/delete/removeStudent.ts diff --git a/request.rest b/request.rest index 9a9efb8..5a82149 100644 --- a/request.rest +++ b/request.rest @@ -54,4 +54,7 @@ GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers GET http://localhost:3003/students/hobbies ### -PUT http://localhost:3003/student/remove-class/:id \ No newline at end of file +PUT http://localhost:3003/student/remove-class/:id + +### +DELETE http://localhost:3003/student/remove/1617312546437 \ No newline at end of file diff --git a/src/endpoints/studant/delete/removeStudent.ts b/src/endpoints/studant/delete/removeStudent.ts new file mode 100644 index 0000000..9e32122 --- /dev/null +++ b/src/endpoints/studant/delete/removeStudent.ts @@ -0,0 +1,23 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' + +const removeStudent = async (req: Request, res: Response): Promise => { + try { + const id = Number(req.params.id) + + if(isNaN(id) === true) throw new Error("Invalid Id.") + + await connection.raw(` + DELETE + FROM Students + WHERE id = "${id}" + `) + + res.status(200).send('Student removed successfully.') + + } catch (error) { + console.log(error.message) + res.status(400).send(error.message) + } +} +export default removeStudent \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ba1f452..f86f18c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import getStudentAge from './endpoints/both/getAge' import getTeacherByClass from './endpoints/teacher/get/getTeacherByClass' import getStudentsByHobbies from './endpoints/studant/get/getStudentsByHobbies' import removeStudentFromClass from './endpoints/studant/delete/removeStudentsFromClass' +import removeStudent from './endpoints/studant/delete/removeStudent' app.get('/students/hobbies', getStudentsByHobbies) app.get('/search/age', getStudentAge) @@ -18,3 +19,4 @@ app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) app.put('/update/class', changeClass) app.put('/student/remove-class/:id', removeStudentFromClass) +app.delete('/student/remove/:id', removeStudent) From 21e72fc5bb3dbf35d8c99ac3f71f9bd73c4d4f3b Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Sun, 4 Apr 2021 23:57:03 +0100 Subject: [PATCH 14/22] IMplementado funcionalidade de remover professor da turma. --- .../teacher/delete/removeTeacherFromClass.ts | 23 +++++++++++++++++++ src/index.ts | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 src/endpoints/teacher/delete/removeTeacherFromClass.ts diff --git a/src/endpoints/teacher/delete/removeTeacherFromClass.ts b/src/endpoints/teacher/delete/removeTeacherFromClass.ts new file mode 100644 index 0000000..60fbf81 --- /dev/null +++ b/src/endpoints/teacher/delete/removeTeacherFromClass.ts @@ -0,0 +1,23 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' + +const removeTeacherFromClass = async (req: Request, res: Response): Promise => { + try { + const id = Number(req.params.id) + + if(isNaN(id) === true) throw new Error("Invalid Id.") + + await connection.raw(` + UPDATE Teachers + SET class_id = null + WHERE id = "${id}" + `) + + res.status(200).send('Teacher removed successfully.') + + } catch (error) { + console.log(error.message) + res.status(400).send(error.message) + } +} +export default removeTeacherFromClass \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f86f18c..7afd2f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import getTeacherByClass from './endpoints/teacher/get/getTeacherByClass' import getStudentsByHobbies from './endpoints/studant/get/getStudentsByHobbies' import removeStudentFromClass from './endpoints/studant/delete/removeStudentsFromClass' import removeStudent from './endpoints/studant/delete/removeStudent' +import removeTeacherFromClass from './endpoints/teacher/delete/removeTeacherFromClass' app.get('/students/hobbies', getStudentsByHobbies) app.get('/search/age', getStudentAge) @@ -19,4 +20,5 @@ app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) app.put('/update/class', changeClass) app.put('/student/remove-class/:id', removeStudentFromClass) +app.put('/teacher/remove-class/:id', removeTeacherFromClass) app.delete('/student/remove/:id', removeStudent) From 47208965c9ce174327dd0caa8fbef02cd1b1066b Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Mon, 5 Apr 2021 00:14:51 +0100 Subject: [PATCH 15/22] =?UTF-8?q?Implementado=20funcionalidade=20de=20alte?= =?UTF-8?q?rar=20m=C3=B3dulo=20da=20turma.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request.rest | 16 ++++++++----- src/endpoints/class/put/changeModule.ts | 30 +++++++++++++++++++++++++ src/index.ts | 6 +++-- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/endpoints/class/put/changeModule.ts diff --git a/request.rest b/request.rest index 5a82149..da35beb 100644 --- a/request.rest +++ b/request.rest @@ -25,10 +25,10 @@ POST http://localhost:3003/teacher/create Content-Type: application/json { - "name":"João", - "email":"joao@gmail.com", - "birthdate":"1996-04-15", - "speciality": "Backend" + "name":"Caio", + "email":"Caio@gmail.com", + "birthdate":"1950-04-15", + "speciality": "React" } ### @@ -54,7 +54,13 @@ GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers GET http://localhost:3003/students/hobbies ### -PUT http://localhost:3003/student/remove-class/:id +DELETE http://localhost:3003/student/remove-class/:id + +### +DELETE http://localhost:3003/teacher/remove-class/:id + +### +PUT http://localhost:3003/class/change-module?id=1617547014022&&module=1 ### DELETE http://localhost:3003/student/remove/1617312546437 \ No newline at end of file diff --git a/src/endpoints/class/put/changeModule.ts b/src/endpoints/class/put/changeModule.ts new file mode 100644 index 0000000..6c117a2 --- /dev/null +++ b/src/endpoints/class/put/changeModule.ts @@ -0,0 +1,30 @@ +import { connection } from "../../../connection"; +import { Request, Response } from 'express' + +const changeModule = async (req: Request, res: Response): Promise => { + try { + const query = { + module: Number(req.query.module), + id: Number(req.query.id) + } + + if(isNaN(query.id) === true){ + throw new Error('Invalid id.') + } else if(isNaN(query.module) === true){ + throw new Error('Invalid module.') + } + + await connection.raw(` + UPDATE Class + SET module = ${query.module} + WHERE id = "${query.id}" + `) + + res.status(200).send('Module updated successfully.') + + } catch (error) { + console.log(error.message) + res.status(400).send(error.message) + } +} +export default changeModule \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 7afd2f3..25a0bee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import getStudentsByHobbies from './endpoints/studant/get/getStudentsByHobbies' import removeStudentFromClass from './endpoints/studant/delete/removeStudentsFromClass' import removeStudent from './endpoints/studant/delete/removeStudent' import removeTeacherFromClass from './endpoints/teacher/delete/removeTeacherFromClass' +import changeModule from './endpoints/class/put/changeModule' app.get('/students/hobbies', getStudentsByHobbies) app.get('/search/age', getStudentAge) @@ -19,6 +20,7 @@ app.post ('/class/create', createClass) app.post('/student/create', createStudant) app.post ('/teacher/create', createTeacher) app.put('/update/class', changeClass) -app.put('/student/remove-class/:id', removeStudentFromClass) -app.put('/teacher/remove-class/:id', removeTeacherFromClass) +app.put('/class/change-module', changeModule) +app.delete('/student/remove-class/:id', removeStudentFromClass) +app.delete('/teacher/remove-class/:id', removeTeacherFromClass) app.delete('/student/remove/:id', removeStudent) From e53236d603c5ace8799a121648821dc01a5e2f05 Mon Sep 17 00:00:00 2001 From: shidoshi93 Date: Mon, 5 Apr 2021 12:32:12 +0100 Subject: [PATCH 16/22] =?UTF-8?q?Refatora=C3=A7=C3=A3o=20final.=20Projeto?= =?UTF-8?q?=20conclu=C3=ADdo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request.rest | 28 +++++++++---------- src/endpoints/class/post/createClass.ts | 6 ++-- src/endpoints/class/put/changeClass.ts | 11 ++++++-- src/endpoints/class/put/changeModule.ts | 2 +- src/endpoints/studant/delete/removeStudent.ts | 2 +- .../studant/delete/removeStudentsFromClass.ts | 2 +- src/endpoints/studant/post/createStudant.ts | 2 +- .../teacher/delete/removeTeacherFromClass.ts | 2 +- .../teacher/get/getTeacherByClass.ts | 2 +- src/endpoints/teacher/post/createTeacher.ts | 2 +- 10 files changed, 33 insertions(+), 26 deletions(-) diff --git a/request.rest b/request.rest index da35beb..8291cc8 100644 --- a/request.rest +++ b/request.rest @@ -14,10 +14,10 @@ POST http://localhost:3003/class/create Content-Type: application/json { - "name":"Turma IPA", - "start_date":"2021-06-01", - "end_date":"2022-12-01", - "type_class": "Integral" + "name":"Turma Neil-na-night.", + "start_date":"2022-03-01", + "end_date":"2022-09-01", + "type_class": "Noturna" } ### @@ -25,10 +25,10 @@ POST http://localhost:3003/teacher/create Content-Type: application/json { - "name":"Caio", - "email":"Caio@gmail.com", - "birthdate":"1950-04-15", - "speciality": "React" + "name":"Neil", + "email":"Neil@gmail.com", + "birthdate":"1970-04-15", + "speciality": "Redux" } ### @@ -36,9 +36,9 @@ PUT http://localhost:3003/update/class Content-Type: application/json { - "tableName": "Teachers", - "peapleClassId": "1617546212494", - "peapleNewClassId": "1617547014022" + "tableName": "Students", + "peapleClassId": "1617566013084", + "peapleNewClassId": "1617619560126" } ### @@ -54,13 +54,13 @@ GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers GET http://localhost:3003/students/hobbies ### -DELETE http://localhost:3003/student/remove-class/:id +PUT http://localhost:3003/class/change-module?id=1617547014022&&module=1 ### -DELETE http://localhost:3003/teacher/remove-class/:id +DELETE http://localhost:3003/student/remove-class/1617566013084 ### -PUT http://localhost:3003/class/change-module?id=1617547014022&&module=1 +DELETE http://localhost:3003/teacher/remove-class/:id ### DELETE http://localhost:3003/student/remove/1617312546437 \ No newline at end of file diff --git a/src/endpoints/class/post/createClass.ts b/src/endpoints/class/post/createClass.ts index 1b0beab..16a3d61 100644 --- a/src/endpoints/class/post/createClass.ts +++ b/src/endpoints/class/post/createClass.ts @@ -11,14 +11,14 @@ const createClass = async ( let nameClass = req.body.name if (req.body.type_class === 'Noturna') { if (!req.body.name.includes('-na-night')) { - throw new Error('Nomes de turmas noturnas precisam terminar com -na-nigth.') + throw new Error('Nomes de turmas noturnas precisam terminar com -na-night.') } else { nameClass = req.body.name } } await connection.raw( - `INSERT INTO Class (id, name, start_date, end_date, type_class) + `INSERT INTO Class (id, class_name, start_date, end_date, type_class) VALUES( "${Date.now()}", "${nameClass}", @@ -28,7 +28,7 @@ const createClass = async ( )` ) - res.status(201).send('Turma criada com sucesso!') + res.status(201).send({message: 'Turma criada com sucesso!'}) } catch (error) { diff --git a/src/endpoints/class/put/changeClass.ts b/src/endpoints/class/put/changeClass.ts index 41f5314..13b3de8 100644 --- a/src/endpoints/class/put/changeClass.ts +++ b/src/endpoints/class/put/changeClass.ts @@ -12,7 +12,14 @@ const changeClass = async (req: Request, peapleNewClassId: req.body.peapleNewClassId } - //verificar se estudante existe + let valueRes: string = "" + if(body.tableName.toLowerCase() === 'teachers'){ + valueRes = "The Teacher was insert in class successfully." + } + + if(body.tableName.toLowerCase() === 'students'){ + valueRes = "The Student was insert in class successfully." + } if(body.tableName !== 'Teachers' && body.tableName !== 'Students'){ errorCode = 422 @@ -28,7 +35,7 @@ const changeClass = async (req: Request, throw new Error('Invalid talbleName parameter.') } else { await updateClassStudant(body.peapleClassId, body.peapleNewClassId, body.tableName) - res.status(200).end(`${body.tableName} updated successfully`) + res.status(200).send({message: String(valueRes)}) } } catch (error) { diff --git a/src/endpoints/class/put/changeModule.ts b/src/endpoints/class/put/changeModule.ts index 6c117a2..d933e13 100644 --- a/src/endpoints/class/put/changeModule.ts +++ b/src/endpoints/class/put/changeModule.ts @@ -20,7 +20,7 @@ const changeModule = async (req: Request, res: Response): Promise => { WHERE id = "${query.id}" `) - res.status(200).send('Module updated successfully.') + res.status(200).send({message: 'Module updated successfully.'}) } catch (error) { console.log(error.message) diff --git a/src/endpoints/studant/delete/removeStudent.ts b/src/endpoints/studant/delete/removeStudent.ts index 9e32122..71d142a 100644 --- a/src/endpoints/studant/delete/removeStudent.ts +++ b/src/endpoints/studant/delete/removeStudent.ts @@ -13,7 +13,7 @@ const removeStudent = async (req: Request, res: Response): Promise => { WHERE id = "${id}" `) - res.status(200).send('Student removed successfully.') + res.status(200).send({message: 'Student removed successfully.'}) } catch (error) { console.log(error.message) diff --git a/src/endpoints/studant/delete/removeStudentsFromClass.ts b/src/endpoints/studant/delete/removeStudentsFromClass.ts index ac0e0ba..4380a70 100644 --- a/src/endpoints/studant/delete/removeStudentsFromClass.ts +++ b/src/endpoints/studant/delete/removeStudentsFromClass.ts @@ -13,7 +13,7 @@ const removeStudentFromClass = async (req: Request, res: Response): Promise => SELECT C.class_name, T.id, - T.teachers_name, + T.teacher_name, T.email, T.birthdate, T.speciality diff --git a/src/endpoints/teacher/post/createTeacher.ts b/src/endpoints/teacher/post/createTeacher.ts index 17e616d..a0fa0b4 100644 --- a/src/endpoints/teacher/post/createTeacher.ts +++ b/src/endpoints/teacher/post/createTeacher.ts @@ -20,7 +20,7 @@ const createTeacher = async ( "${req.body.speciality}" )`) - res.status(201).send('Professor criado com sucesso!') + res.status(201).send({message: 'Professor criado com sucesso!'}) } catch (error) { if(error.message.includes('speciality')){ From d3cc9f3130433f758313e3d5e9626e1a1adbc9fa Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Mon, 5 Apr 2021 12:38:48 +0100 Subject: [PATCH 17/22] Update README.md --- README.md | 98 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 978a24d..2b94624 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,65 @@ -## LabenuSystem: - -Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização. - -Ele deve possuir, ao menos, as 3 entidades importantes: - -1. Estudantes - - Representa estudantes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e os principais hobbies dele. - -2. Docente - - Representa docentes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e todas as especialidades dele. Há 7 especialidades: React, Redux, CSS, Testes, Typescript, Programação Orientada a Objetos e Backend - -3. Turma - - Toda turma é composta das seguintes características: id, nome, data de início, data de término, lista de professores responsáveis, uma lista de alunos e módulo atual em que a turma está. - - O módulo pode assumir os valores de 1 a 7 ou `undefined`, indicando que as aulas dessa turma ainda não começaram. Para esse exercício, vamos considerar que existam dois tipos de turma: integral ou noturna. Há uma restrição para o nome das turmas noturnas: tem que terminar com `-na-night`. - -As funcionalidades básicas são: - -→ Criar estudante; - -→ Criar docente; - -→ Criar turma; - -→ Adicionar estudante na turma; - -→ Adicionar docente na turma; - -→ Pegar a idade de algum estudante a partir do id +# LabenuSystem + +## :memo: Funcionalidades +* Criar estudante +* Criar docente +* Criar turma +* Adicionar estudante a turma +* Adicionar docente a turma +* Pegar a idade de algum estudante a partir do ID +* Exibir estudantes de uma turma +* Exibir docentes de uma turma +* Exibir estudantes que possuam o mesmo hobby +* Remover estudante de uma turma +* Remover estudante do curso +* Remover docente de uma turma +* Mudar turma de módulo + +## 💻 Documentação +Teste as rotas com a documentação, basta importar ela para seu postman. + +[Postman - LabenuSystem](https://documenter.getpostman.com/view/14146800/TzCQb737) + +## ✨ Tecnologias +Esse projeto foi desenvolvido com as seguintes tecnologias: + +* Node +* Express +* Typescript +* Cors +* Knex +* MySQL +* Dotenv + +## 🚀 Como executar +* Clone o repositório +``` +$https://github.com/future4code/epps-labenu-system8 + ``` +* Instale as dependências com +``` +npm install + ``` +* Crie um arquivo .env +``` +touch .env + ``` +* Preencha o arquivo .env +``` +DB_HOST = Coloque aqui seu endereço do banco de dados +DB_USER = Coloque aqui seu usuário +DB_PASSWORD = Coloque aqui sua senha +DB_SCHEMA = Coloque aqui o nome do banco de dados + ``` +* Crie as tabelas com + ``` +npm run tables + ``` +* Inicie o servidor com + ``` +npm run dev + ``` + + ## Desenvolvido por: + - [Bruno Vallim] + - [Daniel Ribeiro](https://www.linkedin.com/in/daniel-ribeiro-59b739140/) From 0a57f602960eb452d73017af34a5103bd8218a8a Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Mon, 5 Apr 2021 12:39:32 +0100 Subject: [PATCH 18/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b94624..0f12929 100644 --- a/README.md +++ b/README.md @@ -61,5 +61,5 @@ npm run dev ``` ## Desenvolvido por: - - [Bruno Vallim] + - Bruno Vallim - [Daniel Ribeiro](https://www.linkedin.com/in/daniel-ribeiro-59b739140/) From 712c52906aaf67af4100922b81ff336f8051bb5d Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Mon, 5 Apr 2021 12:41:10 +0100 Subject: [PATCH 19/22] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f12929..10831aa 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ Esse projeto foi desenvolvido com as seguintes tecnologias: ## 🚀 Como executar * Clone o repositório -``` -$https://github.com/future4code/epps-labenu-system8 - ``` +* +(https://github.com/future4code/epps-labenu-system8) + * Instale as dependências com ``` npm install From 4b76078c5f35c30c8f6afa03f431b1a4638fb2b2 Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Mon, 5 Apr 2021 12:41:35 +0100 Subject: [PATCH 20/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10831aa..05ef7d3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Esse projeto foi desenvolvido com as seguintes tecnologias: ## 🚀 Como executar * Clone o repositório * -(https://github.com/future4code/epps-labenu-system8) +https://github.com/future4code/epps-labenu-system8 * Instale as dependências com ``` From 10251d0a54916a2db91e79ff2fa1f13e65ea4e41 Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Mon, 5 Apr 2021 12:42:05 +0100 Subject: [PATCH 21/22] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 05ef7d3..ffc10ae 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ Esse projeto foi desenvolvido com as seguintes tecnologias: * Dotenv ## 🚀 Como executar -* Clone o repositório -* +* Clone o repositório: + https://github.com/future4code/epps-labenu-system8 * Instale as dependências com From fa3a2f308a0071d177e37d64334e32a7ff511718 Mon Sep 17 00:00:00 2001 From: Daniel Ribeiro <47466677+Shidoshi93@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:57:40 +0100 Subject: [PATCH 22/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffc10ae..1138f89 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ touch .env DB_HOST = Coloque aqui seu endereço do banco de dados DB_USER = Coloque aqui seu usuário DB_PASSWORD = Coloque aqui sua senha -DB_SCHEMA = Coloque aqui o nome do banco de dados +DB_NAME = Coloque aqui o nome do banco de dados ``` * Crie as tabelas com ```