From a1dfb7b7fe0586b152d5a2348a7f8dff10f2d005 Mon Sep 17 00:00:00 2001 From: Vitorduarte0 Date: Wed, 20 Apr 2022 16:14:55 -0300 Subject: [PATCH 01/12] subindo setup do projeto --- .gitignore | 4 ++++ package.json | 37 +++++++++++++++++++++++++++++++++++++ src/app.ts | 16 ++++++++++++++++ src/classes/Docente.ts | 15 +++++++++++++++ src/classes/Estudante.ts | 16 ++++++++++++++++ src/classes/Turma.ts | 14 ++++++++++++++ src/classes/Usuarios.ts | 20 ++++++++++++++++++++ src/data/connections.ts | 16 ++++++++++++++++ src/data/migrations.ts | 0 src/index.ts | 17 +++++++++++++++++ tsconfig.json | 12 ++++++++++++ 11 files changed, 167 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/app.ts create mode 100644 src/classes/Docente.ts create mode 100644 src/classes/Estudante.ts create mode 100644 src/classes/Turma.ts create mode 100644 src/classes/Usuarios.ts create mode 100644 src/data/connections.ts create mode 100644 src/data/migrations.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ece3ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..07c43f7 --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "vaughan-labenu-system5", + "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": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "tsc && node ./build/index.js", + "dev": "ts-node-dev ./src/index.ts" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/future4code/Vaughan-labenu-system5.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/future4code/Vaughan-labenu-system5/issues" + }, + "homepage": "https://github.com/future4code/Vaughan-labenu-system5#readme", + "dependencies": { + "@types/knex": "^0.16.1", + "cors": "^2.8.5", + "dotenv": "^16.0.0", + "express": "^4.17.3", + "knex": "^1.0.7", + "mysql": "^2.18.1", + "typescript": "^4.6.3", + "uuid": "^8.3.2" + }, + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/express": "^4.17.13", + "@types/uuid": "^8.3.4" + } +} diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..d28d82d --- /dev/null +++ b/src/app.ts @@ -0,0 +1,16 @@ +import express from 'express' +import cors from 'cors' +import { AddressInfo } from "net"; +export const app = express() + +app.use(express.json()) +app.use(cors()) + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost: ${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); \ No newline at end of file diff --git a/src/classes/Docente.ts b/src/classes/Docente.ts new file mode 100644 index 0000000..021b1dc --- /dev/null +++ b/src/classes/Docente.ts @@ -0,0 +1,15 @@ +import { Usuarios } from "./Usuarios"; +export class Docente extends Usuarios{ + especialidades: string[] + constructor( + nome: string, + email: string, + data_nasc: string, + turma_id: string + ){ + super(nome, email, data_nasc, turma_id) + } + public retornaProfessor(): string{ + return this.nome + } +} \ No newline at end of file diff --git a/src/classes/Estudante.ts b/src/classes/Estudante.ts new file mode 100644 index 0000000..c69e82d --- /dev/null +++ b/src/classes/Estudante.ts @@ -0,0 +1,16 @@ +import { Usuarios } from "./Usuarios"; + +export class Estudante extends Usuarios{ + hobbies: string[] + constructor( + nome: string, + email: string, + data_nasc: string, + turma_id:string + ){ + super(nome, email, data_nasc, turma_id) + } + public retornaData(): string{ + return this.nome + } +} \ No newline at end of file diff --git a/src/classes/Turma.ts b/src/classes/Turma.ts new file mode 100644 index 0000000..8300d03 --- /dev/null +++ b/src/classes/Turma.ts @@ -0,0 +1,14 @@ +import { v4 as uuidv4 } from 'uuid'; +export class Turma { + id: string + nome: string + modulo: string + constructor(nome:string, modulo:string) { + this.id = uuidv4 () + this.nome = nome + this.modulo = modulo + } + public retornaTurma(): string{ + return this.nome + } +} \ No newline at end of file diff --git a/src/classes/Usuarios.ts b/src/classes/Usuarios.ts new file mode 100644 index 0000000..4668136 --- /dev/null +++ b/src/classes/Usuarios.ts @@ -0,0 +1,20 @@ +import { v4 as uuidv4 } from 'uuid'; +export class Usuarios { + id: string + nome: string + email: string + data_nasc: string + turma_id: string + constructor( + nome: string, + email: string, + data_nasc: string, + turma_id: string + ){ + this.id = uuidv4() + this.nome = nome + this.email = email + this.data_nasc = data_nasc + this.turma_id = turma_id + } +} \ No newline at end of file diff --git a/src/data/connections.ts b/src/data/connections.ts new file mode 100644 index 0000000..7e9bc15 --- /dev/null +++ b/src/data/connections.ts @@ -0,0 +1,16 @@ +import knex from "knex" +import dotenv from "dotenv" + +dotenv.config() + +export const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: 3306, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME, + multipleStatements: true + } +}) \ No newline at end of file diff --git a/src/data/migrations.ts b/src/data/migrations.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..98f4f0f --- /dev/null +++ b/src/index.ts @@ -0,0 +1,17 @@ +import { app } from "./app" +import { Docente } from "./Classes/Docente" +import { Estudante } from "./Classes/Estudante" +import { Turma } from "./Classes/Turma" + +const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") +console.log(estudante) +console.log(estudante.retornaData()) + +const docente: Docente = new Docente("Ana", "Ana@gmail.com", "12/02/2004", "1") +console.log(docente) +console.log(docente.retornaProfessor()) + +const turma: Turma = new Turma("Vaughan", "modulo 5") +console.log(turma) +console.log(turma.retornaTurma()) +app.post('/criar/tarefa') \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a67f97f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "es6", /* Specify ECMAScript target version */ + "module": "commonjs", /* Specify module code generation */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + "outDir": "./build", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. */ + "removeComments": true, /* Do not emit comments to output. */ + "noImplicitAny": true , /* Raise error on declarations with an implied 'any' type. */ + "esModuleInterop": true + } +} \ No newline at end of file From e0e6a1a5f26b780ccc9caafec85fdd0561bd079e Mon Sep 17 00:00:00 2001 From: Vitorduarte0 Date: Thu, 21 Apr 2022 00:09:28 -0300 Subject: [PATCH 02/12] subindo migration, mas falta inserir dados as tapelas --- src/classes/Turma.ts | 9 +++++ src/data/estudante.json | 37 +++++++++++++++++++++ src/data/migrations.ts | 66 +++++++++++++++++++++++++++++++++++++ src/data/turma.json | 18 ++++++++++ src/endPoints/criarTurma.ts | 11 +++++++ src/index.ts | 7 +++- tsconfig.json | 3 +- 7 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 src/data/estudante.json create mode 100644 src/data/turma.json create mode 100644 src/endPoints/criarTurma.ts diff --git a/src/classes/Turma.ts b/src/classes/Turma.ts index 8300d03..9553333 100644 --- a/src/classes/Turma.ts +++ b/src/classes/Turma.ts @@ -1,3 +1,4 @@ +import { Request, Response } from 'express'; import { v4 as uuidv4 } from 'uuid'; export class Turma { id: string @@ -11,4 +12,12 @@ export class Turma { public retornaTurma(): string{ return this.nome } + + async criarTurma(req: Request, res: Response) { + try { + + } catch (error) { + + } + } } \ No newline at end of file diff --git a/src/data/estudante.json b/src/data/estudante.json new file mode 100644 index 0000000..238d6c3 --- /dev/null +++ b/src/data/estudante.json @@ -0,0 +1,37 @@ +[ + { + "id": "1", + "nome": "Vitor", + "email": "vitor@gmail.com", + "data_nasc": "17/06/2003", + "turma_id": "1" + }, + { + "id": "2", + "nome": "Ana", + "email": "Ana@gmail.com", + "data_nasc": "25/02/2004", + "turma_id": "2" + }, + { + "id": "3", + "nome": "Diane", + "email": "Diane@gmail.com", + "data_nasc": "04/08/2001", + "turma_id": "3" + }, + { + "id": "4", + "nome": "Gabriela", + "email": "Gabriela@gmail.com", + "data_nasc": "04/09/2002", + "turma_id": "4" + }, + { + "id": "5", + "nome": "Ronald", + "email": "Ronald@gmail.com", + "data_nasc": "09/08/2001", + "turma_id": "4" + } +] \ No newline at end of file diff --git a/src/data/migrations.ts b/src/data/migrations.ts index e69de29..2b89065 100644 --- a/src/data/migrations.ts +++ b/src/data/migrations.ts @@ -0,0 +1,66 @@ +import { connection } from "./connections"; +import turma from "./turma.json" +import estudante from "./estudante.json" +const printError = (error: any) => { console.log(error.sqlMessage || error.message) } +const createTable =() => connection.raw(` + CREATE TABLE IF NOT EXISTS turma( + id VARCHAR(255) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL, + modulo VARCHAR(255) DEFAULT 0 + ); + + CREATE TABLE IF NOT EXISTS estudante( + id VARCHAR(255) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE + data_nasc DATE NOT NULL, + turma_id VARCHAR(255) NOT NULL + FOREIGN KEY (turma_id) REFERENCES turma(id) + ); + + CREATE TABLE IF NOT EXISTS docente( + id VARCHAR(255) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE + data_nasc DATE NOT NULL, + turma_id VARCHAR(255) NOT NULL + FOREIGN KEY (turma_id) REFERENCES turma(id) + ); + + CREATE TABLE IF NOT EXISTS hobby( + id VARCHAR(255) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL + ); + CREATE TABLE IF NOT EXISTS especialidade( + id VARCHAR(255) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL + ); + + CREATE TABLE IF NOT EXISTS docente_especialidade( + id VARCHAR(255) PRIMARY KEY, + docente_id VARCHAR(255) NOT NULL + especialidade_id VARCHAR(255) NOT NULL + FOREIGN KEY (docente_id) REFERENCES docente(id) + FOREIGN KEY (especialidade_id) REFERENCES especialidade(id) + ); + + CREATE TABLE IF NOT EXISTS estudante_hobby( + id VARCHAR(255) PRIMARY KEY, + estudante_id VARCHAR(255) NOT NULL + hobby_id VARCHAR(255) NOT NULL + FOREIGN KEY (estudante_id) REFERENCES docente(id) + FOREIGN KEY (hobby_id) REFERENCES especialidade(id) + ); +`) +.then(() => console.log("Tabelas criadas")) +.catch(printError) + +const insertTurma = () => connection("turma") +.insert(turma) +.then(()=> console.log("Turmas criadas com sucesso")) +.catch(printError) + +const insertEstudante = () => connection("estudante") +.insert(estudante) +.then(()=> console.log("Turmas criadas com sucesso")) +.catch(printError) \ No newline at end of file diff --git a/src/data/turma.json b/src/data/turma.json new file mode 100644 index 0000000..5b86216 --- /dev/null +++ b/src/data/turma.json @@ -0,0 +1,18 @@ +[ + { + "id": "1", + "nome": "Vaughan" + }, + { + "id": "2", + "nome": "Gebru" + }, + { + "id": "3", + "nome": "Alan Coope" + }, + { + "id": "4", + "nome": "zuckerberg" + } +] \ No newline at end of file diff --git a/src/endPoints/criarTurma.ts b/src/endPoints/criarTurma.ts new file mode 100644 index 0000000..fa76c57 --- /dev/null +++ b/src/endPoints/criarTurma.ts @@ -0,0 +1,11 @@ +import { Request, Response } from 'express'; +export class CriarTurma { + + async criarTurma(req: Request, res: Response) { + try { + + } catch (error) { + + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 98f4f0f..79dbb82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { app } from "./app" import { Docente } from "./Classes/Docente" import { Estudante } from "./Classes/Estudante" import { Turma } from "./Classes/Turma" +import { CriarTurma } from "./endPoints/criarTurma" const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") console.log(estudante) @@ -14,4 +15,8 @@ console.log(docente.retornaProfessor()) const turma: Turma = new Turma("Vaughan", "modulo 5") console.log(turma) console.log(turma.retornaTurma()) -app.post('/criar/tarefa') \ No newline at end of file + +const criarTurma: CriarTurma = new CriarTurma +let iza = criarTurma.criarTurma + +app.post('/criar/tarefa', iza) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a67f97f..922e922 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "rootDir": "./src", /* Specify the root directory of input files. */ "removeComments": true, /* Do not emit comments to output. */ "noImplicitAny": true , /* Raise error on declarations with an implied 'any' type. */ - "esModuleInterop": true + "esModuleInterop": true, + "resolveJsonModule": true } } \ No newline at end of file From 642c0a859618b999d9acb6400785a8ee6ef19330 Mon Sep 17 00:00:00 2001 From: Vitorduarte0 Date: Thu, 21 Apr 2022 20:43:39 -0300 Subject: [PATCH 03/12] =?UTF-8?q?subindo=20parte=20final=20do=20migrations?= =?UTF-8?q?=20mais=20cria=C3=A7=C3=A3o=20dos=20dadosdos=20mokados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++-- src/data/docente.json | 37 ++++++++++++++++++++ src/data/docenteEspecialidade.json | 27 +++++++++++++++ src/data/especialidade.json | 22 ++++++++++++ src/data/estudante.json | 10 +++--- src/data/hobbiesEstudante.json | 27 +++++++++++++++ src/data/hobby.json | 22 ++++++++++++ src/data/migrations.ts | 54 ++++++++++++++++++++++++++++-- 8 files changed, 196 insertions(+), 9 deletions(-) create mode 100644 src/data/docente.json create mode 100644 src/data/docenteEspecialidade.json create mode 100644 src/data/especialidade.json create mode 100644 src/data/hobbiesEstudante.json create mode 100644 src/data/hobby.json diff --git a/package.json b/package.json index 07c43f7..346f59b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "tsc && node ./build/index.js", - "dev": "ts-node-dev ./src/index.ts" + "dev": "ts-node-dev ./src/index.ts", + "migrations": "tsnd ./src/data/migrations.ts" }, "repository": { "type": "git", @@ -32,6 +33,7 @@ "devDependencies": { "@types/cors": "^2.8.12", "@types/express": "^4.17.13", - "@types/uuid": "^8.3.4" + "@types/uuid": "^8.3.4", + "ts-node-dev": "^1.1.8" } } diff --git a/src/data/docente.json b/src/data/docente.json new file mode 100644 index 0000000..5baee63 --- /dev/null +++ b/src/data/docente.json @@ -0,0 +1,37 @@ +[ + { + "id": "1", + "nome": "Flavio", + "email": "Flavio@gmail.com", + "data_nasc": "1995-03-20", + "turma_id": "1" + }, + { + "id": "2", + "nome": "Iza", + "email": "Iza@gmail.com", + "data_nasc": "1994-06-20", + "turma_id": "2" + }, + { + "id": "3", + "nome": "Paulinha", + "email": "paulinha@gmail.com", + "data_nasc": "1992-08-20", + "turma_id": "3" + }, + { + "id": "4", + "nome": "Roberto", + "email": "Roberto@gmail.com", + "data_nasc": "1999-04-14", + "turma_id": "4" + }, + { + "id": "5", + "nome": "Gabriel", + "email": "Gabriel@gmail.com", + "data_nasc": "1989-11-06", + "turma_id": "4" + } +] \ No newline at end of file diff --git a/src/data/docenteEspecialidade.json b/src/data/docenteEspecialidade.json new file mode 100644 index 0000000..2a1a7b0 --- /dev/null +++ b/src/data/docenteEspecialidade.json @@ -0,0 +1,27 @@ +[ + { + "id": "1", + "docente_id": "1", + "especialidade_id": "1" + }, + { + "id": "2", + "docente_id": "2", + "especialidade_id": "2" + }, + { + "id": "3", + "docente_id": "3", + "especialidade_id": "3" + }, + { + "id": "4", + "docente_id": "4", + "especialidade_id": "4" + }, + { + "id": "5", + "docente_id": "5", + "especialidade_id": "5" + } +] \ No newline at end of file diff --git a/src/data/especialidade.json b/src/data/especialidade.json new file mode 100644 index 0000000..46c52df --- /dev/null +++ b/src/data/especialidade.json @@ -0,0 +1,22 @@ +[ + { + "id": "1", + "nome": "Js" + }, + { + "id": "2", + "nome": "Css" + }, + { + "id": "3", + "nome": "React" + }, + { + "id": "4", + "nome": "Typescript" + }, + { + "id": "5", + "nome": "POO (Programação Orientada a Objetos)" + } +] \ No newline at end of file diff --git a/src/data/estudante.json b/src/data/estudante.json index 238d6c3..232d5e2 100644 --- a/src/data/estudante.json +++ b/src/data/estudante.json @@ -3,35 +3,35 @@ "id": "1", "nome": "Vitor", "email": "vitor@gmail.com", - "data_nasc": "17/06/2003", + "data_nasc": "2003-06-17", "turma_id": "1" }, { "id": "2", "nome": "Ana", "email": "Ana@gmail.com", - "data_nasc": "25/02/2004", + "data_nasc": "1995-03-20", "turma_id": "2" }, { "id": "3", "nome": "Diane", "email": "Diane@gmail.com", - "data_nasc": "04/08/2001", + "data_nasc": "1994-04-28", "turma_id": "3" }, { "id": "4", "nome": "Gabriela", "email": "Gabriela@gmail.com", - "data_nasc": "04/09/2002", + "data_nasc": "1996-11-04", "turma_id": "4" }, { "id": "5", "nome": "Ronald", "email": "Ronald@gmail.com", - "data_nasc": "09/08/2001", + "data_nasc": "1993-04-10", "turma_id": "4" } ] \ No newline at end of file diff --git a/src/data/hobbiesEstudante.json b/src/data/hobbiesEstudante.json new file mode 100644 index 0000000..993a7eb --- /dev/null +++ b/src/data/hobbiesEstudante.json @@ -0,0 +1,27 @@ +[ + { + "id": "1", + "estudante_id": "1", + "hobby_id": "1" + }, + { + "id": "2", + "estudante_id": "2", + "hobby_id": "2" + }, + { + "id": "3", + "estudante_id": "3", + "hobby_id": "3" + }, + { + "id": "4", + "estudante_id": "4", + "hobby_id": "4" + }, + { + "id": "5", + "estudante_id": "5", + "hobby_id": "5" + } +] \ No newline at end of file diff --git a/src/data/hobby.json b/src/data/hobby.json new file mode 100644 index 0000000..0ca8468 --- /dev/null +++ b/src/data/hobby.json @@ -0,0 +1,22 @@ +[ + { + "id": "1", + "nome": "assistir séries de tv" + }, + { + "id": "2", + "nome": "jogar videogames" + }, + { + "id": "3", + "nome": "passear de bike" + }, + { + "id": "4", + "nome": "cantar" + }, + { + "id": "5", + "nome": "jogar xadrez" + } +] \ No newline at end of file diff --git a/src/data/migrations.ts b/src/data/migrations.ts index 2b89065..663864b 100644 --- a/src/data/migrations.ts +++ b/src/data/migrations.ts @@ -1,7 +1,13 @@ import { connection } from "./connections"; import turma from "./turma.json" import estudante from "./estudante.json" +import docente from "./docente.json" +import hobby from "./hobby.json" +import especialidade from "./especialidade.json" +import docenteEspecialidade from "./docenteEspecialidade.json" +import hobbiesEstudante from "./hobbiesEstudante.json" const printError = (error: any) => { console.log(error.sqlMessage || error.message) } + const createTable =() => connection.raw(` CREATE TABLE IF NOT EXISTS turma( id VARCHAR(255) PRIMARY KEY, @@ -31,6 +37,7 @@ const createTable =() => connection.raw(` id VARCHAR(255) PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL ); + CREATE TABLE IF NOT EXISTS especialidade( id VARCHAR(255) PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL @@ -51,16 +58,59 @@ const createTable =() => connection.raw(` FOREIGN KEY (estudante_id) REFERENCES docente(id) FOREIGN KEY (hobby_id) REFERENCES especialidade(id) ); + `) +//criando tabelas .then(() => console.log("Tabelas criadas")) .catch(printError) +//inserindo Turma const insertTurma = () => connection("turma") .insert(turma) .then(()=> console.log("Turmas criadas com sucesso")) .catch(printError) +//inserindo Estudante const insertEstudante = () => connection("estudante") .insert(estudante) -.then(()=> console.log("Turmas criadas com sucesso")) -.catch(printError) \ No newline at end of file +.then(()=> console.log("Estudante criado com sucesso")) +.catch(printError) + +//inserindo docente +const insertDocente = () => connection("docente") +.insert(docente) +.then(()=> console.log("Docente criado com sucesso")) +.catch(printError) + +//inserindo hobby +const insertHobby = () => connection("hobby") +.insert(hobby) +.then(()=> console.log("Hobby criado com sucesso")) +.catch(printError) + +//inserindo especialidade +const insertEspecialidade = () => connection("especialidade") +.insert(especialidade) +.then(()=> console.log("Especialidade criada com sucesso")) +.catch(printError) + +//inserindo especialidade do docente +const insertDocenteEspecialidade = () => connection("docente_especialidade") +.insert(docenteEspecialidade) +.then(()=> console.log("Especialidade do docente criada com sucesso")) +.catch(printError) + +//inserindo hobby do estudante +const insertHobbyEstudante = () => connection("estudante_hobby") +.insert(hobbiesEstudante) +.then(()=> console.log("Hobby do estudante criado com sucesso")) +.catch(printError) + +createTable() +.then(insertTurma) +.then(insertEstudante) +.then(insertDocente) +.then(insertHobby) +.then(insertEspecialidade) +.then(insertDocenteEspecialidade) +.then(insertHobbyEstudante) \ No newline at end of file From eb104c4e805403ebb697182f6bf594eec7789b41 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 22 Apr 2022 09:39:26 -0300 Subject: [PATCH 04/12] =?UTF-8?q?altera=C3=A7=C3=A3o=20no=20migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/migrations.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/data/migrations.ts b/src/data/migrations.ts index 663864b..9b47c1e 100644 --- a/src/data/migrations.ts +++ b/src/data/migrations.ts @@ -11,51 +11,51 @@ const printError = (error: any) => { console.log(error.sqlMessage || error.messa const createTable =() => connection.raw(` CREATE TABLE IF NOT EXISTS turma( id VARCHAR(255) PRIMARY KEY, - name VARCHAR(255) UNIQUE NOT NULL, + nome VARCHAR(255) UNIQUE NOT NULL, modulo VARCHAR(255) DEFAULT 0 ); CREATE TABLE IF NOT EXISTS estudante( id VARCHAR(255) PRIMARY KEY, - name VARCHAR(255) UNIQUE NOT NULL, - email VARCHAR(255) NOT NULL UNIQUE + nome VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, data_nasc DATE NOT NULL, - turma_id VARCHAR(255) NOT NULL + turma_id VARCHAR(255) NOT NULL, FOREIGN KEY (turma_id) REFERENCES turma(id) ); CREATE TABLE IF NOT EXISTS docente( id VARCHAR(255) PRIMARY KEY, - name VARCHAR(255) UNIQUE NOT NULL, - email VARCHAR(255) NOT NULL UNIQUE + nome VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, data_nasc DATE NOT NULL, - turma_id VARCHAR(255) NOT NULL + turma_id VARCHAR(255) NOT NULL, FOREIGN KEY (turma_id) REFERENCES turma(id) ); CREATE TABLE IF NOT EXISTS hobby( id VARCHAR(255) PRIMARY KEY, - name VARCHAR(255) UNIQUE NOT NULL + nome VARCHAR(255) UNIQUE NOT NULL ); CREATE TABLE IF NOT EXISTS especialidade( id VARCHAR(255) PRIMARY KEY, - name VARCHAR(255) UNIQUE NOT NULL + nome VARCHAR(255) UNIQUE NOT NULL ); CREATE TABLE IF NOT EXISTS docente_especialidade( id VARCHAR(255) PRIMARY KEY, - docente_id VARCHAR(255) NOT NULL - especialidade_id VARCHAR(255) NOT NULL - FOREIGN KEY (docente_id) REFERENCES docente(id) + docente_id VARCHAR(255) NOT NULL, + especialidade_id VARCHAR(255) NOT NULL, + FOREIGN KEY (docente_id) REFERENCES docente(id), FOREIGN KEY (especialidade_id) REFERENCES especialidade(id) ); CREATE TABLE IF NOT EXISTS estudante_hobby( id VARCHAR(255) PRIMARY KEY, - estudante_id VARCHAR(255) NOT NULL - hobby_id VARCHAR(255) NOT NULL - FOREIGN KEY (estudante_id) REFERENCES docente(id) + estudante_id VARCHAR(255) NOT NULL, + hobby_id VARCHAR(255) NOT NULL, + FOREIGN KEY (estudante_id) REFERENCES docente(id), FOREIGN KEY (hobby_id) REFERENCES especialidade(id) ); From bdc4c415688acc9c614655b64387541728da65b5 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 22 Apr 2022 10:56:21 -0300 Subject: [PATCH 05/12] =?UTF-8?q?cria=C3=A7=C3=A3o=20de=20alguns=20endpoin?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/Turma.ts | 7 ------- src/data/migrations.ts | 4 ++-- src/endPoints/buscarTurmasAtivas.ts | 22 ++++++++++++++++++++++ src/endPoints/criarEstudante.ts | 29 +++++++++++++++++++++++++++++ src/endPoints/criarTurma.ts | 19 +++++++++++++++++-- src/endPoints/mudarModulo.ts | 25 +++++++++++++++++++++++++ src/index.ts | 20 ++++++++++++++++++-- 7 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 src/endPoints/buscarTurmasAtivas.ts create mode 100644 src/endPoints/criarEstudante.ts create mode 100644 src/endPoints/mudarModulo.ts diff --git a/src/classes/Turma.ts b/src/classes/Turma.ts index 9553333..e48d8d8 100644 --- a/src/classes/Turma.ts +++ b/src/classes/Turma.ts @@ -13,11 +13,4 @@ export class Turma { return this.nome } - async criarTurma(req: Request, res: Response) { - try { - - } catch (error) { - - } - } } \ No newline at end of file diff --git a/src/data/migrations.ts b/src/data/migrations.ts index 9b47c1e..6cec046 100644 --- a/src/data/migrations.ts +++ b/src/data/migrations.ts @@ -17,7 +17,7 @@ const createTable =() => connection.raw(` CREATE TABLE IF NOT EXISTS estudante( id VARCHAR(255) PRIMARY KEY, - nome VARCHAR(255) UNIQUE NOT NULL, + nome VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, data_nasc DATE NOT NULL, turma_id VARCHAR(255) NOT NULL, @@ -26,7 +26,7 @@ const createTable =() => connection.raw(` CREATE TABLE IF NOT EXISTS docente( id VARCHAR(255) PRIMARY KEY, - nome VARCHAR(255) UNIQUE NOT NULL, + nome VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, data_nasc DATE NOT NULL, turma_id VARCHAR(255) NOT NULL, diff --git a/src/endPoints/buscarTurmasAtivas.ts b/src/endPoints/buscarTurmasAtivas.ts new file mode 100644 index 0000000..f3296c9 --- /dev/null +++ b/src/endPoints/buscarTurmasAtivas.ts @@ -0,0 +1,22 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export class BuscarTurma { + async buscarTurmasAtivas(req: Request, res: Response): Promise { + let errorCode = 400 + try { + let result = await connection("turma") + .select("*") + .where("modulo", "<>", "0") + + if(result.length < 1) { + errorCode = 422 + throw new Error("Nenhuma turma encontrada") + } + res.status(200).send(result) + } + catch (e) { + res.status(errorCode).send(e.message) + } + } +} \ No newline at end of file diff --git a/src/endPoints/criarEstudante.ts b/src/endPoints/criarEstudante.ts new file mode 100644 index 0000000..d052bd1 --- /dev/null +++ b/src/endPoints/criarEstudante.ts @@ -0,0 +1,29 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; +import { v4 as uuidv4 } from 'uuid'; + + +export class CriarEstudante { + async criarEstudante(req: Request, res: Response) { + let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id} = req.body + if (!nome || !email || !data_nasc || !turma_id) { + errorCode = 422 + throw new Error("Preencha todos os campos") + } + await connection("estudante") + .insert({ + id: uuidv4(), + nome: nome, + email: email, + data_nasc: data_nasc, + turma_id: turma_id + }) + res.status(201).send("Estudante criado com sucesso") + } + catch(e) { + res.status(errorCode).send(e.message) + } + } +} \ No newline at end of file diff --git a/src/endPoints/criarTurma.ts b/src/endPoints/criarTurma.ts index fa76c57..ef14014 100644 --- a/src/endPoints/criarTurma.ts +++ b/src/endPoints/criarTurma.ts @@ -1,11 +1,26 @@ import { Request, Response } from 'express'; +import { connection } from '../data/connections'; +import { v4 as uuidv4 } from 'uuid'; + export class CriarTurma { - async criarTurma(req: Request, res: Response) { + async criarTurma(req: Request, res: Response): Promise { + let errorCode = 400 try { + let {nome} = req.body + if(!nome || nome === undefined) { + errorCode = 422 + throw new Error("Insira o nome da turma") + } + await connection("turma") + .insert({ + id: uuidv4(), + nome: nome + }) + res.status(201).send(`Turma ${nome} criada com sucesso!`) } catch (error) { - + res.status(errorCode).send(error.message) } } } \ No newline at end of file diff --git a/src/endPoints/mudarModulo.ts b/src/endPoints/mudarModulo.ts new file mode 100644 index 0000000..229ab75 --- /dev/null +++ b/src/endPoints/mudarModulo.ts @@ -0,0 +1,25 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export class MudarModulo { + async mudarModulo (req: Request, res: Response) { + let errorCode = 400 + try { + const {id, modulo} = req.body + if(!id && !modulo) { + errorCode = 422 + throw new Error("Preencha todos os campos") + } + let result = await connection("turma") + .update({ + modulo: modulo + }) + .where("id", "=", id) + + res.sendStatus(200).send(result) + } + catch(e) { + res.sendStatus(errorCode).send(e.message) + } + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 79dbb82..62d9f84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,10 @@ import { app } from "./app" import { Docente } from "./Classes/Docente" import { Estudante } from "./Classes/Estudante" import { Turma } from "./Classes/Turma" +import { BuscarTurma } from "./endPoints/buscarTurmasAtivas" +import { CriarEstudante } from "./endPoints/criarEstudante" import { CriarTurma } from "./endPoints/criarTurma" +import { MudarModulo } from "./endPoints/mudarModulo" const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") console.log(estudante) @@ -17,6 +20,19 @@ console.log(turma) console.log(turma.retornaTurma()) const criarTurma: CriarTurma = new CriarTurma -let iza = criarTurma.criarTurma +let adicionarTurma = criarTurma.criarTurma -app.post('/criar/tarefa', iza) \ No newline at end of file +app.post('/turma', adicionarTurma) + +const buscarTurmas: BuscarTurma = new BuscarTurma +let buscarTurmasAtivas = buscarTurmas.buscarTurmasAtivas + +app.get("/turma", buscarTurmasAtivas) + +const mudarModulo: MudarModulo = new MudarModulo +let mudarModuloTurma = mudarModulo.mudarModulo +app.put("/turma", mudarModuloTurma) + +const criarEstudante: CriarEstudante = new CriarEstudante +let criarNovoEstudante = criarEstudante.criarEstudante +app.post("/estudante", criarNovoEstudante) \ No newline at end of file From 1f51b47f4d1cd4a18be2f10bc9f546c29f533284 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 22 Apr 2022 11:56:52 -0300 Subject: [PATCH 06/12] endpoints criados --- src/classes/Docente.ts | 4 +++- src/endPoints/buscarDocentes.ts | 12 ++++++++++++ src/endPoints/buscarEstudantePorNome.ts | 18 ++++++++++++++++++ src/endPoints/criarDocente.ts | 19 +++++++++++++++++++ src/endPoints/mudarDocenteDeTurma.ts | 21 +++++++++++++++++++++ src/endPoints/mudarEstudanteDeTurma.ts | 21 +++++++++++++++++++++ src/index.ts | 14 +++++++++++++- 7 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 src/endPoints/buscarDocentes.ts create mode 100644 src/endPoints/buscarEstudantePorNome.ts create mode 100644 src/endPoints/criarDocente.ts create mode 100644 src/endPoints/mudarDocenteDeTurma.ts create mode 100644 src/endPoints/mudarEstudanteDeTurma.ts diff --git a/src/classes/Docente.ts b/src/classes/Docente.ts index 021b1dc..1b3ebb4 100644 --- a/src/classes/Docente.ts +++ b/src/classes/Docente.ts @@ -1,11 +1,13 @@ import { Usuarios } from "./Usuarios"; +import { v4 as uuidv4 } from 'uuid'; + export class Docente extends Usuarios{ especialidades: string[] constructor( nome: string, email: string, data_nasc: string, - turma_id: string + turma_id: string ){ super(nome, email, data_nasc, turma_id) } diff --git a/src/endPoints/buscarDocentes.ts b/src/endPoints/buscarDocentes.ts new file mode 100644 index 0000000..2fee4d8 --- /dev/null +++ b/src/endPoints/buscarDocentes.ts @@ -0,0 +1,12 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export const buscarDocentes = async(req: Request, res: Response) => { + try { + const resultado = await connection("docente") + res.status(200).send(resultado) + } + catch(e: any) { + res.send(500).status(e.sqlMessage || e.message) + } +} \ No newline at end of file diff --git a/src/endPoints/buscarEstudantePorNome.ts b/src/endPoints/buscarEstudantePorNome.ts new file mode 100644 index 0000000..aab81a5 --- /dev/null +++ b/src/endPoints/buscarEstudantePorNome.ts @@ -0,0 +1,18 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export const buscarEstudante = async(req: Request, res: Response) => { + const {nome} = req.query + try { + let resultado = await connection("estudante") + .select("*") + .where("nome", "like", `%${nome}%`) + if(resultado.length < 1) { + throw new Error("Estudante não encontrado") + } + res.status(200).send(resultado) + } + catch (e) { + res.status(500).send(e.message || e.sqlMessage) + } +} \ No newline at end of file diff --git a/src/endPoints/criarDocente.ts b/src/endPoints/criarDocente.ts new file mode 100644 index 0000000..53afa6c --- /dev/null +++ b/src/endPoints/criarDocente.ts @@ -0,0 +1,19 @@ +import { Request, Response } from 'express'; +import { Docente } from '../Classes/Docente'; +import { connection } from '../data/connections'; + +export const criarDocente = async(req: Request, res: Response) => { + const {nome, email, data_nasc, turma_id} = req.body + try { + let novoDocente = new Docente(nome, email, data_nasc, turma_id) + + await connection("docente") + .insert(novoDocente) + + res.status(201).send("Docente criado com sucesso") + } + catch(e: any) { + res.status(500).send(e.sqlMessage || e.message) + } +} + diff --git a/src/endPoints/mudarDocenteDeTurma.ts b/src/endPoints/mudarDocenteDeTurma.ts new file mode 100644 index 0000000..416f6df --- /dev/null +++ b/src/endPoints/mudarDocenteDeTurma.ts @@ -0,0 +1,21 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export const mudarTurmaDocente = async(req: Request, res: Response) => { + const {turma_id, docente_id} = req.body + try { + let resultado = await connection("estudante") + .update({ + turma_id: turma_id + }) + .where("id", docente_id) + + if(!turma_id || !docente_id) { + throw new Error("Preencha todos os campos") + } + res.status(200).send(resultado) + } + catch(e: any) { + res.status(500).send(e.sqlMessage || e.message) + } +} \ No newline at end of file diff --git a/src/endPoints/mudarEstudanteDeTurma.ts b/src/endPoints/mudarEstudanteDeTurma.ts new file mode 100644 index 0000000..38c9556 --- /dev/null +++ b/src/endPoints/mudarEstudanteDeTurma.ts @@ -0,0 +1,21 @@ +import { Request, Response } from 'express'; +import { connection } from '../data/connections'; + +export const mudarTurma = async(req: Request, res: Response) => { + const {turma_id, estudante_id} = req.body + try { + await connection("estudante") + .update({ + turma_id: turma_id + }) + .where("id", estudante_id) + + if(!turma_id || !estudante_id) { + throw new Error("Preencha todos os campos") + } + res.status(200).send("O estudante foi remanejado com sucesso") + } + catch(e: any) { + res.status(500).send(e.sqlMessage || e.message) + } +} diff --git a/src/index.ts b/src/index.ts index 62d9f84..c5a41f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,13 @@ import { app } from "./app" import { Docente } from "./Classes/Docente" import { Estudante } from "./Classes/Estudante" import { Turma } from "./Classes/Turma" +import { buscarDocentes } from "./endPoints/buscarDocentes" +import { buscarEstudante } from "./endPoints/buscarEstudantePorNome" import { BuscarTurma } from "./endPoints/buscarTurmasAtivas" +import { criarDocente } from "./endPoints/criarDocente" import { CriarEstudante } from "./endPoints/criarEstudante" import { CriarTurma } from "./endPoints/criarTurma" +import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma" import { MudarModulo } from "./endPoints/mudarModulo" const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") @@ -35,4 +39,12 @@ app.put("/turma", mudarModuloTurma) const criarEstudante: CriarEstudante = new CriarEstudante let criarNovoEstudante = criarEstudante.criarEstudante -app.post("/estudante", criarNovoEstudante) \ No newline at end of file +app.post("/estudante", criarNovoEstudante) + +app.get("/estudante", buscarEstudante) + +app.post("/docente", criarDocente) + +app.get("/docente", buscarDocentes) + +app.put("/docente", mudarTurmaDocente) \ No newline at end of file From e1b48bc16271427096eaa7a219c36689501317a3 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 22 Apr 2022 16:20:52 -0300 Subject: [PATCH 07/12] mudar turma arrumado --- src/classes/Turma.ts | 3 ++- src/classes/Usuarios.ts | 1 + src/endPoints/mudarDocenteDeTurma.ts | 15 +++++++++------ src/index.ts | 3 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/classes/Turma.ts b/src/classes/Turma.ts index e48d8d8..cb9758e 100644 --- a/src/classes/Turma.ts +++ b/src/classes/Turma.ts @@ -1,11 +1,12 @@ import { Request, Response } from 'express'; import { v4 as uuidv4 } from 'uuid'; + export class Turma { id: string nome: string modulo: string constructor(nome:string, modulo:string) { - this.id = uuidv4 () + this.id = uuidv4() this.nome = nome this.modulo = modulo } diff --git a/src/classes/Usuarios.ts b/src/classes/Usuarios.ts index 4668136..9242419 100644 --- a/src/classes/Usuarios.ts +++ b/src/classes/Usuarios.ts @@ -1,4 +1,5 @@ import { v4 as uuidv4 } from 'uuid'; + export class Usuarios { id: string nome: string diff --git a/src/endPoints/mudarDocenteDeTurma.ts b/src/endPoints/mudarDocenteDeTurma.ts index 416f6df..85247d9 100644 --- a/src/endPoints/mudarDocenteDeTurma.ts +++ b/src/endPoints/mudarDocenteDeTurma.ts @@ -4,16 +4,19 @@ import { connection } from '../data/connections'; export const mudarTurmaDocente = async(req: Request, res: Response) => { const {turma_id, docente_id} = req.body try { - let resultado = await connection("estudante") + console.log(turma_id, docente_id) + if(!turma_id || !docente_id) { + throw new Error("Preencha todos os campos") + } + await connection("docente") .update({ turma_id: turma_id }) - .where("id", docente_id) + .where({ + id: docente_id + }) - if(!turma_id || !docente_id) { - throw new Error("Preencha todos os campos") - } - res.status(200).send(resultado) + res.status(200).send("O docente mudou de turma") } catch(e: any) { res.status(500).send(e.sqlMessage || e.message) diff --git a/src/index.ts b/src/index.ts index c5a41f6..5ed3f1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { criarDocente } from "./endPoints/criarDocente" import { CriarEstudante } from "./endPoints/criarEstudante" import { CriarTurma } from "./endPoints/criarTurma" import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma" +import { mudarTurma } from "./endPoints/mudarEstudanteDeTurma" import { MudarModulo } from "./endPoints/mudarModulo" const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") @@ -43,6 +44,8 @@ app.post("/estudante", criarNovoEstudante) app.get("/estudante", buscarEstudante) +app.put("/estudante", mudarTurma) + app.post("/docente", criarDocente) app.get("/docente", buscarDocentes) From 769d76cb44a047d755aa7e946b762cb434ffc91d Mon Sep 17 00:00:00 2001 From: Vitorduarte0 Date: Fri, 22 Apr 2022 16:24:51 -0300 Subject: [PATCH 08/12] =?UTF-8?q?subindo=20trata=C3=A7=C3=A3o=20de=20erro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endPoints/criarDocente.ts | 44 +++++++++++++++++- src/endPoints/criarEstudante.ts | 81 ++++++++++++++++++++++----------- src/index.ts | 18 ++++---- 3 files changed, 106 insertions(+), 37 deletions(-) diff --git a/src/endPoints/criarDocente.ts b/src/endPoints/criarDocente.ts index 53afa6c..11c2be2 100644 --- a/src/endPoints/criarDocente.ts +++ b/src/endPoints/criarDocente.ts @@ -3,17 +3,57 @@ import { Docente } from '../Classes/Docente'; import { connection } from '../data/connections'; export const criarDocente = async(req: Request, res: Response) => { + let errorCode = 400; const {nome, email, data_nasc, turma_id} = req.body try { let novoDocente = new Docente(nome, email, data_nasc, turma_id) - + if (!nome && !email && !data_nasc && !turma_id) { + errorCode = 422; + throw new Error("Preencha todos os campos") + } + else if(!nome){ + errorCode = 422; + throw new Error("Preencha seu nome") + } + else if(!email){ + errorCode = 422; + throw new Error("Preencha seu email") + } + else if(!data_nasc){ + errorCode = 422; + throw new Error("Preencha sua data_nasc") + } + else if(!turma_id){ + errorCode = 422; + throw new Error("Preencha sua turma") + } await connection("docente") .insert(novoDocente) res.status(201).send("Docente criado com sucesso") } catch(e: any) { - res.status(500).send(e.sqlMessage || e.message) + switch (e.message) { + case "Preencha todos os campos": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha seu nome": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha seu email": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha sua data_nasc": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha sua turma": + res.status(errorCode).send({ message: e.message }); + break; + + default: + res.status(500).send(e.sqlMessage || e.message); + break; + } } } diff --git a/src/endPoints/criarEstudante.ts b/src/endPoints/criarEstudante.ts index d052bd1..b67797e 100644 --- a/src/endPoints/criarEstudante.ts +++ b/src/endPoints/criarEstudante.ts @@ -1,29 +1,58 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; -import { v4 as uuidv4 } from 'uuid'; - +import { Request, Response } from "express"; +import { connection } from "../data/connections"; +import { v4 as uuidv4 } from "uuid"; export class CriarEstudante { - async criarEstudante(req: Request, res: Response) { - let errorCode = 400 - try { - const {nome, email, data_nasc, turma_id} = req.body - if (!nome || !email || !data_nasc || !turma_id) { - errorCode = 422 - throw new Error("Preencha todos os campos") - } - await connection("estudante") - .insert({ - id: uuidv4(), - nome: nome, - email: email, - data_nasc: data_nasc, - turma_id: turma_id - }) - res.status(201).send("Estudante criado com sucesso") - } - catch(e) { - res.status(errorCode).send(e.message) - } + async criarEstudante(req: Request, res: Response) { + let errorCode = 400; + try { + const { nome, email, data_nasc, turma_id } = req.body; + if (!nome && !email && !data_nasc && !turma_id) { + errorCode = 422; + throw new Error("Preencha todos os campos"); + } else if (!nome) { + errorCode = 422; + throw new Error("Preencha seu nome"); + } else if (!email) { + errorCode = 422; + throw new Error("Preencha seu email"); + } else if (!data_nasc) { + errorCode = 422; + throw new Error("Preencha sua data_nasc"); + } else if (!turma_id) { + errorCode = 422; + throw new Error("Preencha sua turma"); + } + await connection("estudante").insert({ + id: uuidv4(), + nome: nome, + email: email, + data_nasc: data_nasc, + turma_id: turma_id + }); + res.status(201).send({message: "Estudante criado com sucesso"}); + } catch (e) { + switch (e.message) { + case "Preencha todos os campos": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha seu nome": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha seu email": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha sua data_nasc": + res.status(errorCode).send({ message: e.message }); + break; + case "Preencha sua turma": + res.status(errorCode).send({ message: e.message }); + break; + + default: + res.status(500).send(e.sqlMessage || e.message); + break; + } } -} \ No newline at end of file + } +} diff --git a/src/index.ts b/src/index.ts index c5a41f6..974b9a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,17 +11,17 @@ import { CriarTurma } from "./endPoints/criarTurma" import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma" import { MudarModulo } from "./endPoints/mudarModulo" -const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") -console.log(estudante) -console.log(estudante.retornaData()) +// const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") +// console.log(estudante) +// console.log(estudante.retornaData()) -const docente: Docente = new Docente("Ana", "Ana@gmail.com", "12/02/2004", "1") -console.log(docente) -console.log(docente.retornaProfessor()) +// const docente: Docente = new Docente("Ana", "Ana@gmail.com", "12/02/2004", "1") +// console.log(docente) +// console.log(docente.retornaProfessor()) -const turma: Turma = new Turma("Vaughan", "modulo 5") -console.log(turma) -console.log(turma.retornaTurma()) +// const turma: Turma = new Turma("Vaughan", "modulo 5") +// console.log(turma) +// console.log(turma.retornaTurma()) const criarTurma: CriarTurma = new CriarTurma let adicionarTurma = criarTurma.criarTurma From 6a0c7abf2c6bb97d1f26c11dd2e9dd6480d7bfb8 Mon Sep 17 00:00:00 2001 From: Vitorduarte0 Date: Fri, 22 Apr 2022 23:58:48 -0300 Subject: [PATCH 09/12] =?UTF-8?q?subindo=20refatora=C3=A7=C3=B5es=20e=20ma?= =?UTF-8?q?is=20trata=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endPoints/buscarDocentes.ts | 21 ++++---- src/endPoints/buscarEstudantePorNome.ts | 46 +++++++++++------ src/endPoints/buscarTurmasAtivas.ts | 35 ++++++------- src/endPoints/criarDocente.ts | 11 +--- src/endPoints/criarEstudante.ts | 13 ++--- src/endPoints/criarTurma.ts | 45 ++++++++-------- src/endPoints/mudarDocenteDeTurma.ts | 43 ++++++++------- src/endPoints/mudarEstudanteDeTurma.ts | 37 +++++++------ src/endPoints/mudarModulo.ts | 41 +++++++-------- src/index.ts | 69 ++++++++++--------------- 10 files changed, 170 insertions(+), 191 deletions(-) diff --git a/src/endPoints/buscarDocentes.ts b/src/endPoints/buscarDocentes.ts index 2fee4d8..cd64dd7 100644 --- a/src/endPoints/buscarDocentes.ts +++ b/src/endPoints/buscarDocentes.ts @@ -1,12 +1,11 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; -export const buscarDocentes = async(req: Request, res: Response) => { - try { - const resultado = await connection("docente") - res.status(200).send(resultado) - } - catch(e: any) { - res.send(500).status(e.sqlMessage || e.message) - } -} \ No newline at end of file +export const buscarDocentes = async (req: Request, res: Response) => { + try { + const resultado = await connection("docente"); + res.status(200).send(resultado); + } catch (e) { + res.status(500).send({ message: e.sqlMessage || e.message }); + } +}; diff --git a/src/endPoints/buscarEstudantePorNome.ts b/src/endPoints/buscarEstudantePorNome.ts index aab81a5..360ff0c 100644 --- a/src/endPoints/buscarEstudantePorNome.ts +++ b/src/endPoints/buscarEstudantePorNome.ts @@ -1,18 +1,34 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; -export const buscarEstudante = async(req: Request, res: Response) => { - const {nome} = req.query - try { - let resultado = await connection("estudante") - .select("*") - .where("nome", "like", `%${nome}%`) - if(resultado.length < 1) { - throw new Error("Estudante não encontrado") - } - res.status(200).send(resultado) +export const buscarEstudante = async (req: Request, res: Response) => { + const { nome } = req.query; + let errorCode = 400; + try { + if (!nome) { + errorCode = 422; + throw new Error("Por favor insira um nome"); } - catch (e) { - res.status(500).send(e.message || e.sqlMessage) + let resultado = await connection("estudante") + .select("*") + .where("nome", "like", `%${nome}%`); + if (resultado.length < 1) { + errorCode = 422; + throw new Error("Estudante não encontrado"); } -} \ No newline at end of file + res.status(200).send(resultado); + } catch (e) { + switch (e.message) { + case "Por favor insira um nome": + res.status(errorCode).send({ message: e.message }); + break; + case "Estudante não encontrado": + res.status(errorCode).send({ message: e.message }); + break; + + default: + res.status(500).send(e.message || e.sqlMessage); + break; + } + } +}; diff --git a/src/endPoints/buscarTurmasAtivas.ts b/src/endPoints/buscarTurmasAtivas.ts index f3296c9..580ad19 100644 --- a/src/endPoints/buscarTurmasAtivas.ts +++ b/src/endPoints/buscarTurmasAtivas.ts @@ -1,22 +1,21 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; export class BuscarTurma { - async buscarTurmasAtivas(req: Request, res: Response): Promise { - let errorCode = 400 - try { - let result = await connection("turma") - .select("*") - .where("modulo", "<>", "0") + async buscarTurmasAtivas(req: Request, res: Response): Promise { + let errorCode = 400; + try { + let result = await connection("turma") + .select("*") + .where("modulo", "<>", "0"); - if(result.length < 1) { - errorCode = 422 - throw new Error("Nenhuma turma encontrada") - } - res.status(200).send(result) - } - catch (e) { - res.status(errorCode).send(e.message) - } + if (result.length < 1) { + errorCode = 422; + throw new Error("Nenhuma turma encontrada"); + } + res.status(200).send(result); + } catch (e) { + res.status(errorCode).send(e.message); } -} \ No newline at end of file + } +} diff --git a/src/endPoints/criarDocente.ts b/src/endPoints/criarDocente.ts index 11c2be2..9616e27 100644 --- a/src/endPoints/criarDocente.ts +++ b/src/endPoints/criarDocente.ts @@ -7,11 +7,7 @@ export const criarDocente = async(req: Request, res: Response) => { const {nome, email, data_nasc, turma_id} = req.body try { let novoDocente = new Docente(nome, email, data_nasc, turma_id) - if (!nome && !email && !data_nasc && !turma_id) { - errorCode = 422; - throw new Error("Preencha todos os campos") - } - else if(!nome){ + if(!nome){ errorCode = 422; throw new Error("Preencha seu nome") } @@ -34,9 +30,6 @@ export const criarDocente = async(req: Request, res: Response) => { } catch(e: any) { switch (e.message) { - case "Preencha todos os campos": - res.status(errorCode).send({ message: e.message }); - break; case "Preencha seu nome": res.status(errorCode).send({ message: e.message }); break; @@ -51,7 +44,7 @@ export const criarDocente = async(req: Request, res: Response) => { break; default: - res.status(500).send(e.sqlMessage || e.message); + res.status(500).send({message: e.sqlMessage || e.message}); break; } } diff --git a/src/endPoints/criarEstudante.ts b/src/endPoints/criarEstudante.ts index b67797e..aae1113 100644 --- a/src/endPoints/criarEstudante.ts +++ b/src/endPoints/criarEstudante.ts @@ -7,10 +7,7 @@ export class CriarEstudante { let errorCode = 400; try { const { nome, email, data_nasc, turma_id } = req.body; - if (!nome && !email && !data_nasc && !turma_id) { - errorCode = 422; - throw new Error("Preencha todos os campos"); - } else if (!nome) { + if (!nome) { errorCode = 422; throw new Error("Preencha seu nome"); } else if (!email) { @@ -31,11 +28,8 @@ export class CriarEstudante { turma_id: turma_id }); res.status(201).send({message: "Estudante criado com sucesso"}); - } catch (e) { + } catch (e:any) { switch (e.message) { - case "Preencha todos os campos": - res.status(errorCode).send({ message: e.message }); - break; case "Preencha seu nome": res.status(errorCode).send({ message: e.message }); break; @@ -48,9 +42,8 @@ export class CriarEstudante { case "Preencha sua turma": res.status(errorCode).send({ message: e.message }); break; - default: - res.status(500).send(e.sqlMessage || e.message); + res.status(500).send({message: e.sqlMessage || e.message}); break; } } diff --git a/src/endPoints/criarTurma.ts b/src/endPoints/criarTurma.ts index ef14014..680cd51 100644 --- a/src/endPoints/criarTurma.ts +++ b/src/endPoints/criarTurma.ts @@ -1,26 +1,23 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; -import { v4 as uuidv4 } from 'uuid'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; +import { v4 as uuidv4 } from "uuid"; export class CriarTurma { - - async criarTurma(req: Request, res: Response): Promise { - let errorCode = 400 - try { - let {nome} = req.body - if(!nome || nome === undefined) { - errorCode = 422 - throw new Error("Insira o nome da turma") - } - await connection("turma") - .insert({ - id: uuidv4(), - nome: nome - }) - res.status(201).send(`Turma ${nome} criada com sucesso!`) - - } catch (error) { - res.status(errorCode).send(error.message) - } - } -} \ No newline at end of file + async criarTurma(req: Request, res: Response): Promise { + let errorCode = 400; + try { + let { nome } = req.body; + if (!nome || nome === undefined) { + errorCode = 422; + throw new Error("Insira o nome da turma"); + } + await connection("turma").insert({ + id: uuidv4(), + nome: nome + }); + res.status(201).send({ message: `Turma ${nome} criada com sucesso!` }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } +} diff --git a/src/endPoints/mudarDocenteDeTurma.ts b/src/endPoints/mudarDocenteDeTurma.ts index 85247d9..61cba10 100644 --- a/src/endPoints/mudarDocenteDeTurma.ts +++ b/src/endPoints/mudarDocenteDeTurma.ts @@ -1,24 +1,23 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; -export const mudarTurmaDocente = async(req: Request, res: Response) => { - const {turma_id, docente_id} = req.body - try { - console.log(turma_id, docente_id) - if(!turma_id || !docente_id) { - throw new Error("Preencha todos os campos") - } - await connection("docente") - .update({ - turma_id: turma_id - }) - .where({ - id: docente_id - }) - - res.status(200).send("O docente mudou de turma") +export const mudarTurmaDocente = async (req: Request, res: Response) => { + const { turma_id, docente_id } = req.body; + try { + console.log(turma_id, docente_id); + if (!turma_id || !docente_id) { + throw new Error("Preencha todos os campos"); } - catch(e: any) { - res.status(500).send(e.sqlMessage || e.message) - } -} \ No newline at end of file + await connection("docente") + .update({ + turma_id: turma_id + }) + .where({ + id: docente_id + }); + + res.status(200).send({ message: "O docente mudou de turma" }); + } catch (e) { + res.status(500).send({ message: e.sqlMessage || e.message }); + } +}; diff --git a/src/endPoints/mudarEstudanteDeTurma.ts b/src/endPoints/mudarEstudanteDeTurma.ts index 38c9556..fcd727b 100644 --- a/src/endPoints/mudarEstudanteDeTurma.ts +++ b/src/endPoints/mudarEstudanteDeTurma.ts @@ -1,21 +1,20 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; -export const mudarTurma = async(req: Request, res: Response) => { - const {turma_id, estudante_id} = req.body - try { - await connection("estudante") - .update({ - turma_id: turma_id - }) - .where("id", estudante_id) - - if(!turma_id || !estudante_id) { - throw new Error("Preencha todos os campos") - } - res.status(200).send("O estudante foi remanejado com sucesso") - } - catch(e: any) { - res.status(500).send(e.sqlMessage || e.message) +export const mudarTurma = async (req: Request, res: Response) => { + const { turma_id, estudante_id } = req.body; + try { + await connection("estudante") + .update({ + turma_id: turma_id + }) + .where("id", estudante_id); + + if (!turma_id || !estudante_id) { + throw new Error("Preencha todos os campos"); } -} + res.status(200).send({ message: "O estudante foi remanejado com sucesso" }); + } catch (e) { + res.status(500).send({ message: e.sqlMessage || e.message }); + } +}; diff --git a/src/endPoints/mudarModulo.ts b/src/endPoints/mudarModulo.ts index 229ab75..0b4a853 100644 --- a/src/endPoints/mudarModulo.ts +++ b/src/endPoints/mudarModulo.ts @@ -1,25 +1,24 @@ -import { Request, Response } from 'express'; -import { connection } from '../data/connections'; +import { Request, Response } from "express"; +import { connection } from "../data/connections"; export class MudarModulo { - async mudarModulo (req: Request, res: Response) { - let errorCode = 400 - try { - const {id, modulo} = req.body - if(!id && !modulo) { - errorCode = 422 - throw new Error("Preencha todos os campos") - } - let result = await connection("turma") - .update({ - modulo: modulo - }) - .where("id", "=", id) + async mudarModulo(req: Request, res: Response) { + let errorCode = 400; + try { + const { id, modulo } = req.body; + if (!id && !modulo) { + errorCode = 422; + throw new Error("Preencha todos os campos"); + } + const resultado = await connection("turma") + .update({ + modulo: modulo + }) + .where("id", "=", id); - res.sendStatus(200).send(result) - } - catch(e) { - res.sendStatus(errorCode).send(e.message) - } + res.status(200).send(resultado); + } catch (e: any) { + res.sendStatus(errorCode).send({ message: e.message }); } -} \ No newline at end of file + } +} diff --git a/src/index.ts b/src/index.ts index 6ba288c..01cbf1f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,53 +1,38 @@ -import { app } from "./app" -import { Docente } from "./Classes/Docente" -import { Estudante } from "./Classes/Estudante" -import { Turma } from "./Classes/Turma" -import { buscarDocentes } from "./endPoints/buscarDocentes" -import { buscarEstudante } from "./endPoints/buscarEstudantePorNome" -import { BuscarTurma } from "./endPoints/buscarTurmasAtivas" -import { criarDocente } from "./endPoints/criarDocente" -import { CriarEstudante } from "./endPoints/criarEstudante" -import { CriarTurma } from "./endPoints/criarTurma" -import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma" -import { mudarTurma } from "./endPoints/mudarEstudanteDeTurma" -import { MudarModulo } from "./endPoints/mudarModulo" +import { app } from "./app"; +import { buscarDocentes } from "./endPoints/buscarDocentes"; +import { buscarEstudante } from "./endPoints/buscarEstudantePorNome"; +import { BuscarTurma } from "./endPoints/buscarTurmasAtivas"; +import { criarDocente } from "./endPoints/criarDocente"; +import { CriarEstudante } from "./endPoints/criarEstudante"; +import { CriarTurma } from "./endPoints/criarTurma"; +import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma"; +import { mudarTurma } from "./endPoints/mudarEstudanteDeTurma"; +import { MudarModulo } from "./endPoints/mudarModulo"; -// const estudante: Estudante = new Estudante("Diane", "diane@gmail.com", "15/09/2000", "1") -// console.log(estudante) -// console.log(estudante.retornaData()) +const criarTurma: CriarTurma = new CriarTurma(); +let adicionarTurma = criarTurma.criarTurma; -// const docente: Docente = new Docente("Ana", "Ana@gmail.com", "12/02/2004", "1") -// console.log(docente) -// console.log(docente.retornaProfessor()) +app.post("/turma", adicionarTurma); -// const turma: Turma = new Turma("Vaughan", "modulo 5") -// console.log(turma) -// console.log(turma.retornaTurma()) +const buscarTurmas: BuscarTurma = new BuscarTurma(); +let buscarTurmasAtivas = buscarTurmas.buscarTurmasAtivas; -const criarTurma: CriarTurma = new CriarTurma -let adicionarTurma = criarTurma.criarTurma +app.get("/turma", buscarTurmasAtivas); -app.post('/turma', adicionarTurma) +const mudarModulo: MudarModulo = new MudarModulo(); +let mudarModuloTurma = mudarModulo.mudarModulo; +app.put("/turma", mudarModuloTurma); -const buscarTurmas: BuscarTurma = new BuscarTurma -let buscarTurmasAtivas = buscarTurmas.buscarTurmasAtivas +const criarEstudante: CriarEstudante = new CriarEstudante(); +let criarNovoEstudante = criarEstudante.criarEstudante; +app.post("/estudante", criarNovoEstudante); -app.get("/turma", buscarTurmasAtivas) +app.get("/estudante", buscarEstudante); -const mudarModulo: MudarModulo = new MudarModulo -let mudarModuloTurma = mudarModulo.mudarModulo -app.put("/turma", mudarModuloTurma) +app.put("/estudante", mudarTurma); -const criarEstudante: CriarEstudante = new CriarEstudante -let criarNovoEstudante = criarEstudante.criarEstudante -app.post("/estudante", criarNovoEstudante) +app.post("/docente", criarDocente); -app.get("/estudante", buscarEstudante) +app.get("/docente", buscarDocentes); -app.put("/estudante", mudarTurma) - -app.post("/docente", criarDocente) - -app.get("/docente", buscarDocentes) - -app.put("/docente", mudarTurmaDocente) \ No newline at end of file +app.put("/docente", mudarTurmaDocente); From 406a3489aed9b80b17e53f4f00d068139e6a1034 Mon Sep 17 00:00:00 2001 From: Ana Date: Sat, 23 Apr 2022 17:13:16 -0300 Subject: [PATCH 10/12] deixei todos os endpoints iguais --- src/endPoints/buscarTurmasAtivas.ts | 4 +--- src/endPoints/criarEstudante.ts | 17 +++++++---------- src/endPoints/criarTurma.ts | 16 ++++++++-------- src/endPoints/mudarModulo.ts | 8 +++----- src/index.ts | 23 +++++++---------------- 5 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/endPoints/buscarTurmasAtivas.ts b/src/endPoints/buscarTurmasAtivas.ts index 580ad19..9e4e802 100644 --- a/src/endPoints/buscarTurmasAtivas.ts +++ b/src/endPoints/buscarTurmasAtivas.ts @@ -1,8 +1,7 @@ import { Request, Response } from "express"; import { connection } from "../data/connections"; -export class BuscarTurma { - async buscarTurmasAtivas(req: Request, res: Response): Promise { +export const buscarTurmasAtivas = async (req: Request, res: Response): Promise => { let errorCode = 400; try { let result = await connection("turma") @@ -18,4 +17,3 @@ export class BuscarTurma { res.status(errorCode).send(e.message); } } -} diff --git a/src/endPoints/criarEstudante.ts b/src/endPoints/criarEstudante.ts index aae1113..e743b26 100644 --- a/src/endPoints/criarEstudante.ts +++ b/src/endPoints/criarEstudante.ts @@ -1,12 +1,13 @@ import { Request, Response } from "express"; import { connection } from "../data/connections"; import { v4 as uuidv4 } from "uuid"; +import { Estudante } from "../classes/Estudante"; -export class CriarEstudante { - async criarEstudante(req: Request, res: Response) { +export const criarEstudante = async (req: Request, res: Response) => { let errorCode = 400; try { const { nome, email, data_nasc, turma_id } = req.body; + let novoEstudante = new Estudante(nome, email, data_nasc, turma_id) if (!nome) { errorCode = 422; throw new Error("Preencha seu nome"); @@ -20,14 +21,10 @@ export class CriarEstudante { errorCode = 422; throw new Error("Preencha sua turma"); } - await connection("estudante").insert({ - id: uuidv4(), - nome: nome, - email: email, - data_nasc: data_nasc, - turma_id: turma_id - }); + await connection("estudante").insert(novoEstudante); + res.status(201).send({message: "Estudante criado com sucesso"}); + } catch (e:any) { switch (e.message) { case "Preencha seu nome": @@ -48,4 +45,4 @@ export class CriarEstudante { } } } -} + diff --git a/src/endPoints/criarTurma.ts b/src/endPoints/criarTurma.ts index 680cd51..bb76749 100644 --- a/src/endPoints/criarTurma.ts +++ b/src/endPoints/criarTurma.ts @@ -1,23 +1,23 @@ import { Request, Response } from "express"; import { connection } from "../data/connections"; -import { v4 as uuidv4 } from "uuid"; +import { Turma } from "../classes/Turma"; -export class CriarTurma { - async criarTurma(req: Request, res: Response): Promise { +export const criarTurma = async (req: Request, res: Response) => { let errorCode = 400; try { let { nome } = req.body; + let modulo = "0" + let novaTurma = new Turma(nome, modulo) + if (!nome || nome === undefined) { errorCode = 422; throw new Error("Insira o nome da turma"); } - await connection("turma").insert({ - id: uuidv4(), - nome: nome - }); + await connection("turma").insert(novaTurma); + res.status(201).send({ message: `Turma ${nome} criada com sucesso!` }); } catch (error) { res.status(errorCode).send({ message: error.message }); } } -} + diff --git a/src/endPoints/mudarModulo.ts b/src/endPoints/mudarModulo.ts index 0b4a853..6ee942b 100644 --- a/src/endPoints/mudarModulo.ts +++ b/src/endPoints/mudarModulo.ts @@ -1,8 +1,7 @@ import { Request, Response } from "express"; import { connection } from "../data/connections"; -export class MudarModulo { - async mudarModulo(req: Request, res: Response) { +export const mudarTurmaDeModulo = async (req: Request, res: Response) => { let errorCode = 400; try { const { id, modulo } = req.body; @@ -10,15 +9,14 @@ export class MudarModulo { errorCode = 422; throw new Error("Preencha todos os campos"); } - const resultado = await connection("turma") + await connection("turma") .update({ modulo: modulo }) .where("id", "=", id); - res.status(200).send(resultado); + res.status(200).send(`Módulo alterado com sucesso para ${modulo}`); } catch (e: any) { res.sendStatus(errorCode).send({ message: e.message }); } } -} diff --git a/src/index.ts b/src/index.ts index 01cbf1f..206e78c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,31 +1,22 @@ import { app } from "./app"; import { buscarDocentes } from "./endPoints/buscarDocentes"; import { buscarEstudante } from "./endPoints/buscarEstudantePorNome"; -import { BuscarTurma } from "./endPoints/buscarTurmasAtivas"; +import { buscarTurmasAtivas } from "./endPoints/buscarTurmasAtivas"; import { criarDocente } from "./endPoints/criarDocente"; -import { CriarEstudante } from "./endPoints/criarEstudante"; -import { CriarTurma } from "./endPoints/criarTurma"; +import { criarEstudante } from "./endPoints/criarEstudante"; +import { criarTurma } from "./endPoints/criarTurma"; import { mudarTurmaDocente } from "./endPoints/mudarDocenteDeTurma"; import { mudarTurma } from "./endPoints/mudarEstudanteDeTurma"; -import { MudarModulo } from "./endPoints/mudarModulo"; +import { mudarTurmaDeModulo } from "./endPoints/mudarModulo"; -const criarTurma: CriarTurma = new CriarTurma(); -let adicionarTurma = criarTurma.criarTurma; -app.post("/turma", adicionarTurma); - -const buscarTurmas: BuscarTurma = new BuscarTurma(); -let buscarTurmasAtivas = buscarTurmas.buscarTurmasAtivas; +app.post("/turma", criarTurma); app.get("/turma", buscarTurmasAtivas); -const mudarModulo: MudarModulo = new MudarModulo(); -let mudarModuloTurma = mudarModulo.mudarModulo; -app.put("/turma", mudarModuloTurma); +app.put("/turma", mudarTurmaDeModulo); -const criarEstudante: CriarEstudante = new CriarEstudante(); -let criarNovoEstudante = criarEstudante.criarEstudante; -app.post("/estudante", criarNovoEstudante); +app.post("/estudante", criarEstudante); app.get("/estudante", buscarEstudante); From 79a3bc1e833830376b1cd659e87e3fcf80864fca Mon Sep 17 00:00:00 2001 From: Ana Sue Sammi Date: Sat, 23 Apr 2022 17:26:24 -0300 Subject: [PATCH 11/12] Update README.md --- README.md | 61 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 978a24d..a866ce3 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,28 @@ -## 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 + +API desenvolvida para ser utilizada como um sistema organizacional de estudantes, docentes e turmas da Labenu. + +### 🔗 Link da documentação: +https://documenter.getpostman.com/view/19298136/UyrAGchs + +### ✔ O que funciona: +- Criar turma +- Buscar turmas ativas +- Mudar o módulo da turma +- Criar estudante +- Buscar estudantes por nome +- Mudar estudante de turma +- Criar docente +- Buscar docentes +- Mudar docente de turma + +### ❌ O que falta implementar: +- Exibir todas as pessoas pertencentes a uma mesma turma +- Exibir estudantes que tenham o mesmo hobby +- Exibir todos os docentes que tenham uma mesma especialidade +- Exibir todas as pessoas de um mesmo signo + +### Projeto desenvolvido por: +- Ana Sue Sammi +- Diane Silva de Araújo +- Vitor Duarte Passo From c7bbd2b3c8065d8abb5d04b785cb3e09a468061e Mon Sep 17 00:00:00 2001 From: Ana Sue Sammi Date: Sat, 23 Apr 2022 17:27:35 -0300 Subject: [PATCH 12/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a866ce3..b12a3bf 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ https://documenter.getpostman.com/view/19298136/UyrAGchs - Exibir todos os docentes que tenham uma mesma especialidade - Exibir todas as pessoas de um mesmo signo -### Projeto desenvolvido por: +### 👩‍💻👨‍💻 Projeto desenvolvido por: - Ana Sue Sammi - Diane Silva de Araújo - Vitor Duarte Passo