diff --git a/README.md b/README.md index 978a24d..bf6fe8a 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,62 @@ -## LabenuSystem: +

💻 LabeSystem 💻

-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. +

📃 Sobre 📃

+

Projeto de backend desenvolvido conforme proposta da Labenu para criação de uma API para um sistema de uma escola de programação.

-Ele deve possuir, ao menos, as 3 entidades importantes: +Esse sistema possui 3 entidades importantes: -1. Estudantes +

Estudantes

- Representa estudantes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e os principais hobbies dele. +

Representa estudantes da instituição. Eles possuem: id, nome, email, data de nascimento e os principais hobbies deles.

-2. Docente +

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 +

Representa docentes da instituição. Eles possuem: id, nome, email, data de nascimento e todas as especialidades deles. Há 5 especialidades: React, JS, CSS, Typescript, POO.

-3. Turma +

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á. +

Toda turma é composta das seguintes características: id, nome e módulo atual em que a turma está.

+

O módulo pode assumir os valores de 1 a 6, ou 0, indicando que as aulas dessa turma ainda não começaram.

- 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`. +

📝 Documentação 📝

-As funcionalidades básicas são: +

https://documenter.getpostman.com/view/19721031/UzXKXeSC

-→ Criar estudante; +

✅ O que funciona ✅

-→ Criar docente; +* Criar estudante; +* Criar docente; +* Criar turma; +* Mudar aluno de turma; +* Mudar docente de turma; +* Mudar módulo da turma; +* Buscar alunos; +* Buscar docentes; +* Buscar todas as turmas; +* Buscar turmas ativas; -→ Criar turma; +

🛠 Em desenvolvimento 🛠

-→ Adicionar estudante na turma; +* Ao buscar alunos não é exibido a lista de hobbies deles. +* Ao buscar docentes não é exibido a lista de especialidades deles. -→ Adicionar docente na turma; +

👨‍💻 Desenvolvedores 👩‍💻

-→ Pegar a idade de algum estudante a partir do id + + + + + + + + + + + +
+
+ Tiago Hennig
+
+ Raul Rita
+
+ Maria Karolina Freitas
diff --git a/labenu-system/.gitignore b/labenu-system/.gitignore new file mode 100644 index 0000000..9708d9f --- /dev/null +++ b/labenu-system/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/labenu-system/package.json b/labenu-system/package.json new file mode 100644 index 0000000..33a3158 --- /dev/null +++ b/labenu-system/package.json @@ -0,0 +1,31 @@ +{ + "name": "labenu-system", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "ts-node-dev ./src/index.ts", + "start": "node ./build/index.js", + "build": "tsc" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.0.1", + "express": "^4.18.1", + "knex": "^2.1.0", + "mysql": "^2.18.1", + "uuid": "^8.3.2" + }, + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/express": "^4.17.13", + "@types/knex": "^0.16.1", + "@types/node": "^18.0.6", + "@types/uuid": "^8.3.4", + "ts-node-dev": "^2.0.0", + "typescript": "^4.7.4" + } +} diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql new file mode 100644 index 0000000..4ec3ab8 --- /dev/null +++ b/labenu-system/querys.sql @@ -0,0 +1,76 @@ +-- Active: 1658325348046@@35.226.146.116@3306@guimaraes-4211089-raul-rita +USE `guimaraes-4211089-raul-rita`; + +CREATE TABLE LS_Turma( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + modulo ENUM('0','1','2','3','4','5','6') DEFAULT '0' +); + +CREATE TABLE LS_Estudante( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + data_nasc VARCHAR(255) NOT NULL, + turma_id VARCHAR(255), FOREIGN KEY (turma_id) REFERENCES LS_Turma(id) +); + +CREATE TABLE LS_Hobby ( + id VARCHAR(255) PRIMARY KEY, + nome_hobby ENUM("assistir séries de tv", "jogar videogames", "sair com os amigos", "praticar esportes") NOT NULL +); + + + +CREATE TABLE LS_Hobby_Estudante( + id VARCHAR(255) PRIMARY KEY, + id_estudante VARCHAR(255), FOREIGN KEY(id_estudante) REFERENCES LS_Estudante(id), + id_hobby VARCHAR(255), FOREIGN KEY(id_hobby) REFERENCES LS_Hobby(id) +); +SELECT * FROM `LS_Hobby_Estudante`; + +CREATE TABLE LS_Docente( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + data_nasc VARCHAR(255) NOT NULL, + turma_id VARCHAR(255), FOREIGN KEY (turma_id) REFERENCES LS_Turma(id) +); + +SELECT * FROM `LS_Docente_Especialidade`; + +CREATE TABLE LS_Especialidade ( + id VARCHAR(255) PRIMARY KEY, + nome_especialidade ENUM("JS", "CSS", "React", "Typescript", "POO") NOT NULL +); + +ALTER TABLE `LS_Especialidade` +MODIFY COLUMN nome_especialidade VARCHAR(255) NOT NULL; +SELECT * FROM `LS_Especialidade`; + +CREATE TABLE LS_Docente_Especialidade ( + id VARCHAR(255) PRIMARY KEY, + id_docente VARCHAR(255), FOREIGN KEY(id_docente) REFERENCES LS_Docente(id), + id_especialidade VARCHAR(255), FOREIGN KEY(id_especialidade) REFERENCES LS_Especialidade(id) +); + +ALTER TABLE `LS_Turma` +MODIFY COLUMN modulo VARCHAR(255) NOT NULL DEFAULT 0; + +SELECT * FROM `LS_Turma`; + +SELECT * FROM LS_Turma INNER JOIN `LS_Estudante` ON LS_Turma.id = LS_Estudante.turma_id; + +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("1", "react"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("2", "js"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("3", "css"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("4", "typescript"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("5", "poo"); + + +SELECT nome, nome_hobby +FROM LS_Hobby_Estudante + INNER JOIN LS_Estudante + ON LS_Hobby_Estudante.id_estudante = LS_Estudante.id + INNER JOIN LS_Hobby + ON LS_Hobby_Estudante.id_hobby = "8c1fa295-c2b9-4e9f-b62e-7ab486f546af"; \ No newline at end of file diff --git a/labenu-system/request.rest b/labenu-system/request.rest new file mode 100644 index 0000000..e03a016 --- /dev/null +++ b/labenu-system/request.rest @@ -0,0 +1,81 @@ +POST http://localhost:3003/turma/ +Content-Type: application/json + +{ + "nome": "abc", + "modulo": "5" +} + +### + +POST http://localhost:3003/estudante/ +Content-Type: application/json + +{ + "nome": "Maria Karolina", + "email": "mariakarolina@email.com", + "data_nasc": "28/06/1993", + "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", + "hobby": ["Programar", "Nadar", "Dançar"] +} + +### + +POST http://localhost:3003/docente/ +Content-Type: application/json + +{ + "nome": "Juliana", + "email": "juliana@email.com", + "data_nasc": "28/06/1990", + "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", + "especialidade": ["React", "JS", "poo"] +} + +### + +GET http://localhost:3003/turma/ativa + +### + +GET http://localhost:3003/turma/ + +### + +Get http://localhost:3003/estudante/?nome= + +### + +GET http://localhost:3003/docente/ + +### + + + +PUT http://localhost:3003/turma/guimaraes +Content-Type: application/json + +{ + "modulo": "1" +} + +### + +PUT http://localhost:3003/estudante/ +Content-Type: application/json + +{ + "id": "a28cafd1-88e4-42b5-951a-1c075d08b8dd", + "turma": "joy" +} + +### + +PUT http://localhost:3003/docente/ +Content-Type: application/json + +{ + "id": "00800266-93f3-4d5c-b93d-3b6348afd150", + "turma": "joi" +} + diff --git a/labenu-system/src/app.ts b/labenu-system/src/app.ts new file mode 100644 index 0000000..201a5a2 --- /dev/null +++ b/labenu-system/src/app.ts @@ -0,0 +1,19 @@ +import express from "express"; +import cors from "cors" +import { AddressInfo } from "net"; + +const app = express(); + +app.use(express.json()); +app.use(cors()); + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost: ${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); + +export default app; \ No newline at end of file diff --git a/labenu-system/src/classes/Docente.ts b/labenu-system/src/classes/Docente.ts new file mode 100644 index 0000000..94770ce --- /dev/null +++ b/labenu-system/src/classes/Docente.ts @@ -0,0 +1,17 @@ +import { User } from "./User" + + +export class Docente extends User { + + public especialidade?: string[] + + constructor( + id:string, + nome:string, + email:string, + data_nasc:string, + turma_id:string, + ) { + super(id, nome, email, data_nasc, turma_id) + } +} \ No newline at end of file diff --git a/labenu-system/src/classes/Estudante.ts b/labenu-system/src/classes/Estudante.ts new file mode 100644 index 0000000..b81f752 --- /dev/null +++ b/labenu-system/src/classes/Estudante.ts @@ -0,0 +1,17 @@ +import { User } from "./User" + + +export class Estudante extends User{ + public hobby?: string[] + + constructor( + id:string, + nome:string, + email:string, + data_nasc:string, + turma_id:string + ){ + super(id, nome, email, data_nasc, turma_id) + } + + } \ No newline at end of file diff --git a/labenu-system/src/classes/User.ts b/labenu-system/src/classes/User.ts new file mode 100644 index 0000000..31fd930 --- /dev/null +++ b/labenu-system/src/classes/User.ts @@ -0,0 +1,23 @@ +export class User { + public "id": string + public "nome": string + public "email": string + public "data_nasc": string + public "turma_id": string + + constructor( + id:string, + nome:string, + email:string, + data_nasc:string, + turma_id:string + ) + { + console.log("Chamando o constructor da Classe User") + this.id = id, + 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/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts new file mode 100644 index 0000000..b8060ac --- /dev/null +++ b/labenu-system/src/classes/turma.ts @@ -0,0 +1,26 @@ +export enum MODULO { + MODULO_0 = "0", + MODULO_1 = "1", + MODULO_2 = "2", + MODULO_3 = "3", + MODULO_4 = "4", + MODULO_5 = "5", + MODULO_6 = "6", +} + +export class Turma { + "id": string + "nome": string + "modulo": MODULO + + constructor( + id:string, + nome:string, + modulo:MODULO + ) + { + this.id = id; + this.nome = nome; + this.modulo = modulo + } +} diff --git a/labenu-system/src/connection.ts b/labenu-system/src/connection.ts new file mode 100644 index 0000000..c831b73 --- /dev/null +++ b/labenu-system/src/connection.ts @@ -0,0 +1,17 @@ +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_PASSWORD, + database: process.env.DB_SCHEMA + } +}); + +export default connection; \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts b/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts new file mode 100644 index 0000000..9e855de --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts @@ -0,0 +1,31 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarAlunos(req:Request, res:Response) { + + let errorCode = 400 + + try { + + const nome = req.query.nome + + if (!nome) { + const response = await connection("LS_Estudante") + .select("*") + + res.status(200).send(response) + return + } + + const response = await connection("LS_Estudante") + .select("*") + .where("nome", "like", `%${nome}%`) + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts b/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts new file mode 100644 index 0000000..b5e48ab --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts @@ -0,0 +1,19 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarDocentes(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Docente") + .select("*") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts b/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts new file mode 100644 index 0000000..41275db --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts @@ -0,0 +1,19 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarTodasAsTurmas(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Turma") + .select("*") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts b/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts new file mode 100644 index 0000000..51881e9 --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts @@ -0,0 +1,20 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarTurmasAtivas(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Turma") + .select("*") + .where("modulo", "not like", "0") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarDocente.ts b/labenu-system/src/endpoints/Criar/CriarDocente.ts new file mode 100644 index 0000000..3d9860d --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarDocente.ts @@ -0,0 +1,58 @@ +import { Request, Response } from "express"; +import { v4 as generateId } from "uuid"; +import { Docente} from "../../classes/Docente"; +import connection from "../../connection"; + + +export async function criarDocente(req:Request, res:Response):Promise { + let errorCode = 400 + + try { + + const {nome, email, data_nasc, turma_id, especialidade}:Docente = req.body + const id = generateId() + + if(!nome || !email || !data_nasc || !turma_id || !especialidade) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + if (typeof(especialidade) != "object") { + res.status(errorCode).send("A(s) especialidade(s) deve(m) vir em forma de array!") + return + } + + const novoDocente = new Docente(id, nome, email, data_nasc, turma_id) + await connection("LS_Docente") + .insert(novoDocente) + + for (let e of especialidade) { + let buscaEspecialidade = await connection("LS_Especialidade") + .select("id") + .where("nome_especialidade", "like", e.toLowerCase()) + + const response = await connection("LS_Docente") + .select("id") + .where("email", "like", email) + + if (buscaEspecialidade.length === 0) { + await connection("LS_Docente_Especialidade").delete().where("id_docente", "like", response[0].id) + await connection("LS_Docente").delete().where("email", "like", email) + res.send("Uma ou mais especialidades digitadas não existem.") + return + } + + await connection("LS_Docente_Especialidade") + .insert({ + id: generateId(), + id_docente: response[0].id, + id_especialidade: buscaEspecialidade[0].id + }) + } + + res.status(200).send("Docente cadastrado!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarEstudante.ts b/labenu-system/src/endpoints/Criar/CriarEstudante.ts new file mode 100644 index 0000000..74c6a96 --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarEstudante.ts @@ -0,0 +1,64 @@ +import { Request, Response } from "express"; +import { v4 as generateId } from "uuid"; +import { Estudante } from "../../classes/Estudante"; +import connection from "../../connection"; + + +export async function criarEstudante(req:Request, res:Response):Promise { + let errorCode = 400 + + try { + + const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body + const id = generateId() + + if(!nome || !email || !data_nasc || !turma_id) { + errorCode = 404 + res.status(errorCode).send("Todos os campos são obrigatórios.") + } + + if (typeof(hobby) != "object") { + res.status(errorCode).send("O(s) hobby(s) deve(m) vir em forma de array!") + return + } + + const novoEstudante = new Estudante(id, nome, email, data_nasc, turma_id) + + await connection("LS_Estudante") + .insert(novoEstudante) + + for (let h of hobby) { + let buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + + if (buscaHobby.length === 0) { + await connection("LS_Hobby") + .insert({ + id: generateId(), + nome_hobby: h + }) + + buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + } + + const response = await connection("LS_Estudante") + .select("id") + .where("email" ,"like", email) + + await connection("LS_Hobby_Estudante") + .insert({ + id:generateId(), + id_estudante: response[0].id, + id_hobby: buscaHobby[0].id + }) + } + + res.status(200).send("Aluno cadastrado!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarTurma.ts b/labenu-system/src/endpoints/Criar/CriarTurma.ts new file mode 100644 index 0000000..ed48315 --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarTurma.ts @@ -0,0 +1,40 @@ +import { Request, Response } from "express"; +import { v4 as generateId } from "uuid"; +import { MODULO, Turma } from "../../classes/turma"; +import connection from "../../connection"; + + +export async function criarTurma(req:Request, res:Response) :Promise { + let errorCode = 400 + + try { + + const {nome, modulo}:Turma = req.body + const id = generateId() + + if (!(Object.values(MODULO).includes(modulo))) { + errorCode = 404 + res.status(errorCode).send("Módulo inválido!") + return + } + + if(!nome) { + errorCode = 400 + res.status(errorCode).send("Insira o nome da Turma.") + } + + const novaTurma = new Turma(id, nome, modulo) + + await connection("LS_Turma") + .insert(novaTurma) + + res.status(200).send("Turma criada!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} + + + + diff --git a/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts b/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts new file mode 100644 index 0000000..3011bb9 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts @@ -0,0 +1,41 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + +export async function MudarAlunoTurma(req:Request, res:Response) { + let errorCode = 400 + + try { + + const id = req.body.id + const turma = req.body.turma + + const idDaTurma = await connection("LS_Turma") + .select("id") + .where("nome","like", turma) + + if (idDaTurma.length == 0){ + errorCode = 404 + res.status(errorCode).send("A turma não existe.") + return + } + + const buscaAluno = await connection("LS_Estudante") + .select("*") + .where("id", "like", id) + + if (buscaAluno.length == 0) { + errorCode = 404 + res.status(errorCode).send("O aluno digitado não existe.") + return + } + + await connection("LS_Estudante") + .update("turma_id", idDaTurma[0].id) + .where("id", "like", id) + + res.status(200).send("Turma alterada!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts b/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts new file mode 100644 index 0000000..d5c2049 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts @@ -0,0 +1,39 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + +export async function MudarDocenteTurma(req:Request, res:Response) { + let errorCode = 400 + + try { + + const id = req.body.id + const turma = req.body.turma + + const idDaTurma = await connection("LS_Turma") + .select("id") + .where("nome","like", turma) + + if (idDaTurma.length == 0){ + res.status(errorCode).send("A turma não existe.") + return + } + + const buscaDocente = await connection("LS_Docente") + .select("*") + .where("id", "like", id) + + if (buscaDocente.length == 0) { + res.status(errorCode).send("O docente digitado não existe.") + return + } + + await connection("LS_Docente") + .update("turma_id", idDaTurma[0].id) + .where("id", "like", id) + + res.status(200).send("Turma alterada!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts b/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts new file mode 100644 index 0000000..d0ea376 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts @@ -0,0 +1,36 @@ +import { Request, Response } from "express"; +import { MODULO } from "../../classes/turma"; +import connection from "../../connection"; + +export async function MudarTurmaModulo(req:Request, res:Response) { + let errorCode = 400 + + try { + + const nome = req.params.nome + const modulo = req.body.modulo + + if (!(Object.values(MODULO).includes(modulo))) { + res.send("Módulo inválido!") + return + } + + const buscaTurma = await connection("LS_Turma") + .select("*") + .where("nome", "like", nome) + + if (buscaTurma.length == 0) { + res.status(404).send("A turma digitada não existe.") + return + } + + await connection("LS_Turma") + .update("modulo", modulo) + .where("nome", "like", nome) + + res.status(200).send("Módulo alterado!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts new file mode 100644 index 0000000..7b4f970 --- /dev/null +++ b/labenu-system/src/index.ts @@ -0,0 +1,24 @@ +import app from "./app"; +import { criarTurma } from "./endpoints/Criar/CriarTurma"; +import { criarEstudante } from "./endpoints/Criar/CriarEstudante"; +import { criarDocente } from "./endpoints/Criar/CriarDocente"; +import { BuscarTurmasAtivas } from "./endpoints/Buscar/BuscarTurmasAtivas"; +import { BuscarTodasAsTurmas } from "./endpoints/Buscar/BuscarTodasAsTurmas"; +import { BuscarAlunos } from "./endpoints/Buscar/BuscarAlunos"; +import { BuscarDocentes } from "./endpoints/Buscar/BuscarDocentes"; +import { MudarTurmaModulo } from "./endpoints/Mudar/MudarTurmaModulo"; +import { MudarAlunoTurma } from "./endpoints/Mudar/MudarAlunoTurma"; +import { MudarDocenteTurma } from "./endpoints/Mudar/MudarDocenteTurma"; + +app.post('/turma/', criarTurma) +app.post("/estudante/", criarEstudante) +app.post("/docente/", criarDocente) + +app.get('/turma/ativa', BuscarTurmasAtivas) +app.get('/turma/', BuscarTodasAsTurmas) +app.get('/estudante/', BuscarAlunos) +app.get('/docente/', BuscarDocentes) + +app.put('/turma/:nome', MudarTurmaModulo) +app.put('/estudante/', MudarAlunoTurma) +app.put('/docente/', MudarDocenteTurma) diff --git a/labenu-system/tsconfig.json b/labenu-system/tsconfig.json new file mode 100644 index 0000000..f7c1338 --- /dev/null +++ b/labenu-system/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "outDir": "./build", + "rootDir": "./src", + "removeComments": true, + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } + } \ No newline at end of file