From 003eea22c9c550e73c89df98cf30c446f34e6b0d Mon Sep 17 00:00:00 2001 From: Vivian-Oliveira Date: Fri, 2 Apr 2021 20:55:22 +0100 Subject: [PATCH 1/5] atualizacao --- src/endpoints/createClass.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/createClass.ts b/src/endpoints/createClass.ts index 64533c7..742dedf 100644 --- a/src/endpoints/createClass.ts +++ b/src/endpoints/createClass.ts @@ -31,7 +31,7 @@ export default async function createClass( } if(input.tipo === TYPE_CLASS.NOTURNA) { - input.nome = input.nome += "-na-night"; + input.nome = input.nome +="-na-night"; } await connection.raw(` INSERT INTO class ( nome, data_inicio, data_final, modulo) From 6f1b210b3cd25a61d52b70a474b7014227fa60df Mon Sep 17 00:00:00 2001 From: Vivian-Oliveira Date: Sat, 3 Apr 2021 00:07:54 +0100 Subject: [PATCH 2/5] finalizamos endpoints de docentes --- request.rest | 9 +- src/endpoints/addExpertises.ts | 32 +++++++ .../{addStudent.ts => addStudent copy.ts} | 0 src/endpoints/addTeacher.ts | 20 ---- src/endpoints/createTeacher.ts | 92 +++++++++++++++---- src/endpoints/getAge.ts | 14 ++- src/endpoints/teacherExpertise.ts | 30 ++++++ src/index.ts | 9 +- src/types.ts | 37 +++++--- 9 files changed, 176 insertions(+), 67 deletions(-) create mode 100644 src/endpoints/addExpertises.ts rename src/endpoints/{addStudent.ts => addStudent copy.ts} (100%) delete mode 100644 src/endpoints/addTeacher.ts create mode 100644 src/endpoints/teacherExpertise.ts diff --git a/request.rest b/request.rest index c3e4b9f..7735ce4 100644 --- a/request.rest +++ b/request.rest @@ -10,14 +10,15 @@ Content-Type: application/json ### -PUT http://localhost:3003/create-teacher +POST http://localhost:3003/create-teacher Content-Type: application/json { - "nome":"Darvas", - "email": "darvas@labenu.com.br", + "nome":"Vanessa", + "email": "vanessa@labenu.com.br", "data_nasc": "1990-05-20", - "turma_id": 1 + "turma_id": 3 + } ### diff --git a/src/endpoints/addExpertises.ts b/src/endpoints/addExpertises.ts new file mode 100644 index 0000000..8d8cfcd --- /dev/null +++ b/src/endpoints/addExpertises.ts @@ -0,0 +1,32 @@ +import { Request, Response } from "express" +import connection from "../connection" +import { expertise} from "../types" + + +export default async function addExpertises( + req: Request, + res: Response +): Promise { + + try { + const especialidades: expertise = { + especialidade: req.body.especialidade + } + + if ( !req.body.especialidade) { + res.status(400).send('Invalid Parameters test.') + } else { + await connection.raw(` + INSERT INTO expertise (nome) VALUES ( + "${req.body.especialidade}" + ) + `) + res.status(201).send({ message: 'Student created successfully' }) + + } + + + } catch (error) { + res.status(500).send({message: error.message || error.sqlMessage}) + } +} \ No newline at end of file diff --git a/src/endpoints/addStudent.ts b/src/endpoints/addStudent copy.ts similarity index 100% rename from src/endpoints/addStudent.ts rename to src/endpoints/addStudent copy.ts diff --git a/src/endpoints/addTeacher.ts b/src/endpoints/addTeacher.ts deleted file mode 100644 index 15277df..0000000 --- a/src/endpoints/addTeacher.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" - -export default async function addTeacher( - req: Request, - res: Response -): Promise { - - try { - let { id, nome, email, data_nasc, turma_id } = req.body - - await connection("teacher") - .insert({id, nome, email, data_nasc, turma_id}) - res.status(201).send({message: 'Class created succesfully'}) - - - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } -} \ No newline at end of file diff --git a/src/endpoints/createTeacher.ts b/src/endpoints/createTeacher.ts index db5650d..38d77b3 100644 --- a/src/endpoints/createTeacher.ts +++ b/src/endpoints/createTeacher.ts @@ -1,32 +1,86 @@ import { Request, Response } from "express" -import insertTeacher from "../data/insertTeacher" - - +import connection from "../connection" +import { expertise, Teacher, teacher_expertise } from "../types" export default async function createTeacher( req: Request, res: Response ): Promise { - try { - if( - !req.body.nome || - !req.body.email || - !req.body.data_nasc || - !req.body.turma_id - ) - res.status(400).send("Campos obrigatorios") + const input: Teacher = { + nome: req.body.nome, + email: req.body.email, + data_nasc: req.body.data_nasc, + turma_id: req.body.turma_id + } + // const especialidades: expertise = { + // especialidade: req.body.especialidade + // } + // if ( !req.body.especialidade) { + // res.status(400).send('Invalid Parameters test.') + // } else { + // await connection.raw(` + // INSERT INTO expertise (especialidade) VALUES ( + // "${req.body.especialidade}" + // ) + // `) + // } + if (!req.body.nome || !req.body.email || !req.body.data_nasc || !req.body.turma_id) { + res.status(400).send('Invalid Parameters.') + } else { + await connection.raw(` + INSERT INTO teacher (nome, email, data_nasc, turma_id) + VALUES( + "${req.body.nome}", + "${req.body.email}", + "${req.body.data_nasc}", + ${req.body.turma_id} + ); + `) + } - await insertTeacher( - req.body.nome, - req.body.email, - req.body.data_nasc, - req.body.turma_id - ) - res.status(200).send("Professor criado com sucesso!") + + res.status(201).send({ message: 'Student created successfully' }) } catch (error) { res.status(500).send({message: error.message || error.sqlMessage}) } -} \ No newline at end of file + + + +} + + +// import { Request, Response } from "express" +// import insertTeacher from "../data/insertTeacher" + + +// export default async function createTeacher( +// req: Request, +// res: Response +// ): Promise { + +// try { +// if( +// !req.body.nome || +// !req.body.email || +// !req.body.data_nasc || +// !req.body.turma_id +// ) +// res.status(400).send("Campos obrigatorios") + + +// await insertTeacher( +// req.body.nome, +// req.body.email, +// req.body.data_nasc, +// req.body.turma_id +// ) +// res.status(200).send("Professor criado com sucesso!") + + +// } catch (error) { +// res.status(500).send({message: error.message || error.sqlMessage}) +// } +// } \ No newline at end of file diff --git a/src/endpoints/getAge.ts b/src/endpoints/getAge.ts index a4167ac..b6f8dfe 100644 --- a/src/endpoints/getAge.ts +++ b/src/endpoints/getAge.ts @@ -1,14 +1,18 @@ import { Request, Response } from "express" - - +import connection from "../connection" export default async function getAge( req: Request, res: Response ): Promise { - try { - + const id = req.params.id + const result = await connection.raw(` + SELECT * FROM students WHERE id = ${id}; + `) + res.status(201).send({estudante: result[0] }) } catch (error) { - res.status(500).end() + res.status(400).send({ + message: error.message || error.sqlMessage + }) } } \ No newline at end of file diff --git a/src/endpoints/teacherExpertise.ts b/src/endpoints/teacherExpertise.ts new file mode 100644 index 0000000..4c1814e --- /dev/null +++ b/src/endpoints/teacherExpertise.ts @@ -0,0 +1,30 @@ +import { Request, Response } from "express" +import connection from "../connection" +import { teacher_expertise } from "../types" + +export default async function teacherExpertise( + req: Request, + res: Response +): Promise { + + try { + console.log() + const resultExpertise : teacher_expertise = { + docente_id: req.body.docente_id, + especialidade_id: req.body.especialidade_id + } + await connection.raw(` + + INSERT INTO teacher_expertise (docente_id, especialidade_id) + VALUES( + ${req.body.docente_id}, + ${req.body.especialidade_id} + ) + `) + res.status(201).send({ message: 'Student created successfully' }) + + + } catch (error) { + res.status(500).send({message: error.message || error.sqlMessage}) + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index b1058b4..7b820ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,14 @@ import app from "./app" -import addStudent from "./endpoints/addStudent" -import addTeacher from "./endpoints/addTeacher" +import addExpertises from "./endpoints/addExpertises" +import addStudent from "./endpoints/addExpertises" import createClass from "./endpoints/createClass" import createStudent from "./endpoints/createStudent" import createTeacher from "./endpoints/createTeacher" import getAge from "./endpoints/getAge" +import teacherExpertise from "./endpoints/teacherExpertise" -app.put("/", addStudent); -app.put("/", addTeacher); +app.put("/especialidade", addExpertises); +app.post("/teacher-expertise", teacherExpertise); app.put("/create-student", createStudent); app.put("/create-teacher", createTeacher); app.post("/create-class", createClass); diff --git a/src/types.ts b/src/types.ts index 92d5a88..3aadc13 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,26 +1,35 @@ export enum TYPE_CLASS { INTEGRAL = "integral", - NOTURNA = "noturna" + NOTURNA = "noturna", +} +export enum TYPE_TEACHER { + REACT = "react", + REDUX = "redux", + CSS = "css", + TESTES = "testes", + TYPESCRIPT = "typescript", + POOB = "POOB", + BACKEND = "backend", +} +export enum TYPE_STUDENTS { + FILMES = "filmes", + VIDEOGAME = "videogame", + VIOLAO = "violao" } - export type students = { - id: number, nome: string, email: string, data_nasc: Date, turma_id: number }; - export type hobby = { - id: number, - nome: string + nome: string, + hobby: TYPE_STUDENTS } - export type students_hobby = { estudantes_id: number, passatempo_id: number } - export type Class = { nome: string, data_inicio: Date, @@ -28,19 +37,17 @@ export type Class = { modulo: number, tipo: TYPE_CLASS }; - export type Teacher = { - id: number, nome: string, email: string, data_nasc: Date, - turma_id: number + turma_id: number +}; +export type expertise = { + especialidade: TYPE_TEACHER }; export type teacher_expertise = { docente_id: number, - especialidade_id: number + especialidade_id:number }; - -export let classes: Class [] = [] - From b0a73b641d84b0d6cc4ed2843e9136714cc20eb7 Mon Sep 17 00:00:00 2001 From: Vivian-Oliveira Date: Sat, 3 Apr 2021 00:11:52 +0100 Subject: [PATCH 3/5] finalizamos endpoints de docentes --- src/endpoints/addExpertises.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/addExpertises.ts b/src/endpoints/addExpertises.ts index 8d8cfcd..1003511 100644 --- a/src/endpoints/addExpertises.ts +++ b/src/endpoints/addExpertises.ts @@ -21,7 +21,7 @@ export default async function addExpertises( "${req.body.especialidade}" ) `) - res.status(201).send({ message: 'Student created successfully' }) + res.status(201).send({ message: 'Expertises created successfully' }) } From 2d983e7386cf2fcc9460632fb93cad263c772659 Mon Sep 17 00:00:00 2001 From: Vivian-Oliveira Date: Sat, 3 Apr 2021 00:45:04 +0100 Subject: [PATCH 4/5] finalizamos endpoints docente --- src/endpoints/createTeacher.ts | 45 ---------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/endpoints/createTeacher.ts b/src/endpoints/createTeacher.ts index 38d77b3..18ce5d9 100644 --- a/src/endpoints/createTeacher.ts +++ b/src/endpoints/createTeacher.ts @@ -12,19 +12,6 @@ export default async function createTeacher( data_nasc: req.body.data_nasc, turma_id: req.body.turma_id } - // const especialidades: expertise = { - // especialidade: req.body.especialidade - // } - - // if ( !req.body.especialidade) { - // res.status(400).send('Invalid Parameters test.') - // } else { - // await connection.raw(` - // INSERT INTO expertise (especialidade) VALUES ( - // "${req.body.especialidade}" - // ) - // `) - // } if (!req.body.nome || !req.body.email || !req.body.data_nasc || !req.body.turma_id) { res.status(400).send('Invalid Parameters.') } else { @@ -52,35 +39,3 @@ export default async function createTeacher( } -// import { Request, Response } from "express" -// import insertTeacher from "../data/insertTeacher" - - -// export default async function createTeacher( -// req: Request, -// res: Response -// ): Promise { - -// try { -// if( -// !req.body.nome || -// !req.body.email || -// !req.body.data_nasc || -// !req.body.turma_id -// ) -// res.status(400).send("Campos obrigatorios") - - -// await insertTeacher( -// req.body.nome, -// req.body.email, -// req.body.data_nasc, -// req.body.turma_id -// ) -// res.status(200).send("Professor criado com sucesso!") - - -// } catch (error) { -// res.status(500).send({message: error.message || error.sqlMessage}) -// } -// } \ No newline at end of file From ac8acb1aede037ce4838005f30926ab3ca266367 Mon Sep 17 00:00:00 2001 From: Allison Araujo Date: Fri, 2 Apr 2021 21:10:25 -0300 Subject: [PATCH 5/5] Revert "Endpoints post" --- request.rest | 35 -------------------- src/app.ts | 20 ----------- src/connection.ts | 18 ---------- src/data/insertStudent.ts | 15 --------- src/data/insertTeacher.ts | 15 --------- src/data/selectAgeById.ts | 6 ---- src/endpoints/addExpertises.ts | 32 ------------------ src/endpoints/addStudent copy.ts | 14 -------- src/endpoints/createClass.ts | 50 ---------------------------- src/endpoints/createStudent.ts | 29 ---------------- src/endpoints/createTeacher.ts | 41 ----------------------- src/endpoints/getAge.ts | 18 ---------- src/endpoints/teacherExpertise.ts | 30 ----------------- src/index.ts | 47 +++++++++++++++++--------- src/types.ts | 53 ----------------------------- tables/class.sql | 16 --------- tables/students.sql | 21 ------------ tables/tables.sql | 55 +++++++++++++++++++++++++++++++ tables/teacher.sql | 21 ------------ 19 files changed, 87 insertions(+), 449 deletions(-) delete mode 100644 request.rest delete mode 100644 src/app.ts delete mode 100644 src/connection.ts delete mode 100644 src/data/insertStudent.ts delete mode 100644 src/data/insertTeacher.ts delete mode 100644 src/data/selectAgeById.ts delete mode 100644 src/endpoints/addExpertises.ts delete mode 100644 src/endpoints/addStudent copy.ts delete mode 100644 src/endpoints/createClass.ts delete mode 100644 src/endpoints/createStudent.ts delete mode 100644 src/endpoints/createTeacher.ts delete mode 100644 src/endpoints/getAge.ts delete mode 100644 src/endpoints/teacherExpertise.ts delete mode 100644 src/types.ts delete mode 100644 tables/class.sql delete mode 100644 tables/students.sql create mode 100644 tables/tables.sql delete mode 100644 tables/teacher.sql diff --git a/request.rest b/request.rest deleted file mode 100644 index 7735ce4..0000000 --- a/request.rest +++ /dev/null @@ -1,35 +0,0 @@ -POST http://localhost:3003/create-class -Content-Type: application/json - -{ - "nome":"Ada", - "data_inicio": "2019-09-01", - "data_final": "2020-04-01", - "tipo": "integral" -} - -### - -POST http://localhost:3003/create-teacher -Content-Type: application/json - -{ - "nome":"Vanessa", - "email": "vanessa@labenu.com.br", - "data_nasc": "1990-05-20", - "turma_id": 3 - -} - -### - -PUT http://localhost:3003/create-student -Content-Type: application/json - -{ - - "nome":"Allisson", - "email": "allisson@gmail.com", - "data_nasc": "1990-02-17", - "turma_id": 1 -} \ No newline at end of file diff --git a/src/app.ts b/src/app.ts deleted file mode 100644 index 9f82ffb..0000000 --- a/src/app.ts +++ /dev/null @@ -1,20 +0,0 @@ -import express, {Express} from 'express' -import cors from 'cors' -import { AddressInfo } from "net"; - - -const app: Express = express(); - -app.use(express.json()); -app.use(cors()); - -const server = app.listen(process.env.PORT || 3003, () => { - if (server) { - const address = server.address() as AddressInfo; - console.log(`Server is running in http://localhost: ${address.port}`); - } else { - console.error(`Failure upon starting server.`); - } -}); - -export default app; \ No newline at end of file diff --git a/src/connection.ts b/src/connection.ts deleted file mode 100644 index 7a133ce..0000000 --- a/src/connection.ts +++ /dev/null @@ -1,18 +0,0 @@ -import knex from "knex"; -import dotenv from "dotenv"; - -dotenv.config(); - -const connection = knex({ - client: "mysql", - connection: { - host: process.env.DB_HOST, - port: Number(process.env.DB_PORT || "3306"), - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_SCHEMA, - multipleStatements: true - }, -}); - -export default connection \ No newline at end of file diff --git a/src/data/insertStudent.ts b/src/data/insertStudent.ts deleted file mode 100644 index 475ab04..0000000 --- a/src/data/insertStudent.ts +++ /dev/null @@ -1,15 +0,0 @@ -import connection from "../connection"; - -export default async function insertTeacher( - nome: string, - email: string, - data_nasc: Date, - turma_id: number -) { - await connection.insert({ - nome, - email, - data_nasc, - turma_id - }).into('students') -} \ No newline at end of file diff --git a/src/data/insertTeacher.ts b/src/data/insertTeacher.ts deleted file mode 100644 index 2809716..0000000 --- a/src/data/insertTeacher.ts +++ /dev/null @@ -1,15 +0,0 @@ -import connection from "../connection"; - -export default async function insertStudent( - nome: string, - email: string, - data_nasc: Date, - turma_id: number -) { - await connection.insert({ - nome, - email, - data_nasc, - turma_id - }).into('teacher') -} \ No newline at end of file diff --git a/src/data/selectAgeById.ts b/src/data/selectAgeById.ts deleted file mode 100644 index b1e47f5..0000000 --- a/src/data/selectAgeById.ts +++ /dev/null @@ -1,6 +0,0 @@ -import connection from "../connection"; - -export default async function selectAgeById( - id:number) { - const result = await connection('students') -} \ No newline at end of file diff --git a/src/endpoints/addExpertises.ts b/src/endpoints/addExpertises.ts deleted file mode 100644 index 1003511..0000000 --- a/src/endpoints/addExpertises.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" -import { expertise} from "../types" - - -export default async function addExpertises( - req: Request, - res: Response -): Promise { - - try { - const especialidades: expertise = { - especialidade: req.body.especialidade - } - - if ( !req.body.especialidade) { - res.status(400).send('Invalid Parameters test.') - } else { - await connection.raw(` - INSERT INTO expertise (nome) VALUES ( - "${req.body.especialidade}" - ) - `) - res.status(201).send({ message: 'Expertises created successfully' }) - - } - - - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } -} \ No newline at end of file diff --git a/src/endpoints/addStudent copy.ts b/src/endpoints/addStudent copy.ts deleted file mode 100644 index c068c93..0000000 --- a/src/endpoints/addStudent copy.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Request, Response } from "express" - - -export default async function addStudents( - req: Request, - res: Response -): Promise { - - try { - - } catch (error) { - res.status(500).end() - } -} \ No newline at end of file diff --git a/src/endpoints/createClass.ts b/src/endpoints/createClass.ts deleted file mode 100644 index 742dedf..0000000 --- a/src/endpoints/createClass.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" -import { Class, TYPE_CLASS } from "../types" - - -export default async function createClass( - req: Request, - res: Response -): Promise { - - try { - let errorCode = 400; - - const input: Class = { - nome: req.body.nome, - data_inicio:req.body.data_inicio, - data_final:req.body.data_final, - modulo: 0, - tipo: req.body.tipo - } - - if(!input.nome || !input.data_inicio || - !input.data_final || !input.tipo) { - errorCode = 422; - throw new Error("Campos obrigatorios!") - } - - if(input.tipo !== TYPE_CLASS.INTEGRAL && input.tipo !== TYPE_CLASS.NOTURNA) { - errorCode = 422; - throw new Error("Campos obrigatorios!") - - } - if(input.tipo === TYPE_CLASS.NOTURNA) { - input.nome = input.nome +="-na-night"; - } - await connection.raw(` - INSERT INTO class ( nome, data_inicio, data_final, modulo) - VALUES( - "${req.body.nome}", - "${req.body.data_inicio}", - "${req.body.data_final}", - ${input.modulo} - ); - `); - res.status(201).send({ message: 'Class created successfully' }) - - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } -} \ No newline at end of file diff --git a/src/endpoints/createStudent.ts b/src/endpoints/createStudent.ts deleted file mode 100644 index edf3edc..0000000 --- a/src/endpoints/createStudent.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Request, Response } from "express" -import insertStudent from "../data/insertStudent" - - -export default async function createStudent( - req: Request, - res: Response -): Promise { - - try { - - if( - !req.body.nome || - !req.body.email || - !req.body.data_nasc || - !req.body.turma_id - ) - res.status(400).send("Campos obrigatorios") - - await insertStudent( - req.body.nome, - req.body.email, - req.body.data_nasc, - req.body.turma_id - ) - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } -} \ No newline at end of file diff --git a/src/endpoints/createTeacher.ts b/src/endpoints/createTeacher.ts deleted file mode 100644 index 18ce5d9..0000000 --- a/src/endpoints/createTeacher.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" -import { expertise, Teacher, teacher_expertise } from "../types" -export default async function createTeacher( - req: Request, - res: Response -): Promise { - try { - const input: Teacher = { - nome: req.body.nome, - email: req.body.email, - data_nasc: req.body.data_nasc, - turma_id: req.body.turma_id - } - if (!req.body.nome || !req.body.email || !req.body.data_nasc || !req.body.turma_id) { - res.status(400).send('Invalid Parameters.') - } else { - await connection.raw(` - INSERT INTO teacher (nome, email, data_nasc, turma_id) - VALUES( - "${req.body.nome}", - "${req.body.email}", - "${req.body.data_nasc}", - ${req.body.turma_id} - ); - `) - } - - - - res.status(201).send({ message: 'Student created successfully' }) - - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } - - - -} - - diff --git a/src/endpoints/getAge.ts b/src/endpoints/getAge.ts deleted file mode 100644 index b6f8dfe..0000000 --- a/src/endpoints/getAge.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" -export default async function getAge( - req: Request, - res: Response -): Promise { - try { - const id = req.params.id - const result = await connection.raw(` - SELECT * FROM students WHERE id = ${id}; - `) - res.status(201).send({estudante: result[0] }) - } catch (error) { - res.status(400).send({ - message: error.message || error.sqlMessage - }) - } -} \ No newline at end of file diff --git a/src/endpoints/teacherExpertise.ts b/src/endpoints/teacherExpertise.ts deleted file mode 100644 index 4c1814e..0000000 --- a/src/endpoints/teacherExpertise.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Request, Response } from "express" -import connection from "../connection" -import { teacher_expertise } from "../types" - -export default async function teacherExpertise( - req: Request, - res: Response -): Promise { - - try { - console.log() - const resultExpertise : teacher_expertise = { - docente_id: req.body.docente_id, - especialidade_id: req.body.especialidade_id - } - await connection.raw(` - - INSERT INTO teacher_expertise (docente_id, especialidade_id) - VALUES( - ${req.body.docente_id}, - ${req.body.especialidade_id} - ) - `) - res.status(201).send({ message: 'Student created successfully' }) - - - } catch (error) { - res.status(500).send({message: error.message || error.sqlMessage}) - } -} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 7b820ef..6e428fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,32 @@ -import app from "./app" -import addExpertises from "./endpoints/addExpertises" -import addStudent from "./endpoints/addExpertises" -import createClass from "./endpoints/createClass" -import createStudent from "./endpoints/createStudent" -import createTeacher from "./endpoints/createTeacher" -import getAge from "./endpoints/getAge" -import teacherExpertise from "./endpoints/teacherExpertise" - -app.put("/especialidade", addExpertises); -app.post("/teacher-expertise", teacherExpertise); -app.put("/create-student", createStudent); -app.put("/create-teacher", createTeacher); -app.post("/create-class", createClass); -app.get("/get-age/:id", getAge); +import express, {Express} from 'express' +import cors from 'cors' +import { AddressInfo } from "net"; +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 + } +}); + +const app: Express = express(); + +app.use(express.json()); +app.use(cors()); + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost: ${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 3aadc13..0000000 --- a/src/types.ts +++ /dev/null @@ -1,53 +0,0 @@ -export enum TYPE_CLASS { - INTEGRAL = "integral", - NOTURNA = "noturna", -} -export enum TYPE_TEACHER { - REACT = "react", - REDUX = "redux", - CSS = "css", - TESTES = "testes", - TYPESCRIPT = "typescript", - POOB = "POOB", - BACKEND = "backend", -} -export enum TYPE_STUDENTS { - FILMES = "filmes", - VIDEOGAME = "videogame", - VIOLAO = "violao" -} -export type students = { - nome: string, - email: string, - data_nasc: Date, - turma_id: number -}; -export type hobby = { - nome: string, - hobby: TYPE_STUDENTS -} -export type students_hobby = { - estudantes_id: number, - passatempo_id: number -} -export type Class = { - nome: string, - data_inicio: Date, - data_final: Date, - modulo: number, - tipo: TYPE_CLASS -}; -export type Teacher = { - nome: string, - email: string, - data_nasc: Date, - turma_id: number -}; -export type expertise = { - especialidade: TYPE_TEACHER -}; - -export type teacher_expertise = { - docente_id: number, - especialidade_id:number -}; diff --git a/tables/class.sql b/tables/class.sql deleted file mode 100644 index cf0e7f4..0000000 --- a/tables/class.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE class ( -id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -nome VARCHAR(50) NOT NULL, -data_inicio DATE NOT NULL, -data_final DATE NOT NULL, -modulo INT NOT NULL -); - - - - - - - - - diff --git a/tables/students.sql b/tables/students.sql deleted file mode 100644 index c17e117..0000000 --- a/tables/students.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE students ( -id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -nome VARCHAR(50) NOT NULL, -email VARCHAR(50) NOT NULL UNIQUE, -data_nasc DATE NOT NULL, -turma_id INT NOT NULL, -FOREIGN KEY (turma_id) REFERENCES class(id) -); - -CREATE TABLE hobby ( -id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -nome VARCHAR(50) NOT NULL -); - -CREATE TABLE students_hobby ( -estudantes_id INT NOT NULL AUTO_INCREMENT, -passatempo_id INT NOT NULL, -PRIMARY KEY(estudantes_id, passatempo_id), -FOREIGN KEY(estudantes_id) REFERENCES students(id), -FOREIGN KEY(passatempo_id) REFERENCES hobby(id) -); diff --git a/tables/tables.sql b/tables/tables.sql new file mode 100644 index 0000000..0712ff0 --- /dev/null +++ b/tables/tables.sql @@ -0,0 +1,55 @@ +CREATE TABLE class ( +id INT NOT NULL PRIMARY KEY, +nome VARCHAR(50) NOT NULL, +data_inicio DATE NOT NULL, +data_final DATE NOT NULL, +modulo INT NOT NULL +); + +CREATE TABLE teacher ( +id INT NOT NULL PRIMARY KEY, +nome VARCHAR(50) NOT NULL, +email VARCHAR(50) NOT NULL UNIQUE, +data_nasc DATE NOT NULL, +turma_id INT NOT NULL, +FOREIGN KEY (turma_id) REFERENCES class(id) +); + +CREATE TABLE expertise ( +id INT NOT NULL PRIMARY KEY, +nome VARCHAR(50) NOT NULL +); + +CREATE TABLE teacher_expertise ( +docente_id_especialidade_id INT NOT NULL PRIMARY KEY, +docente_id INT NOT NULL, +especialidade_id INT NOT NULL, +FOREIGN KEY(docente_id) REFERENCES teacher(id), +FOREIGN KEY(especialidade_id) REFERENCES expertise(id) +); + +CREATE TABLE students ( +id INT NOT NULL PRIMARY KEY, +nome VARCHAR(50) NOT NULL, +email VARCHAR(50) NOT NULL UNIQUE, +data_nasc DATE NOT NULL, +turma_id INT NOT NULL, +FOREIGN KEY (turma_id) REFERENCES class(id) +); + +CREATE TABLE hobby ( +id INT NOT NULL PRIMARY KEY, +nome VARCHAR(50) NOT NULL +); + +CREATE TABLE students_hobby ( +estudantes_id_passatempo_id INT NOT NULL PRIMARY KEY, +estudantes_id INT NOT NULL, +passatempo_id INT NOT NULL, +FOREIGN KEY(estudantes_id) REFERENCES students(id), +FOREIGN KEY(passatempo_id) REFERENCES hobby(id) +); + + + + diff --git a/tables/teacher.sql b/tables/teacher.sql deleted file mode 100644 index 43be497..0000000 --- a/tables/teacher.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE teacher ( -id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -nome VARCHAR(50) NOT NULL, -email VARCHAR(50) NOT NULL UNIQUE, -data_nasc DATE NOT NULL, -turma_id INT NOT NULL, -FOREIGN KEY (turma_id) REFERENCES class(id) -); - -CREATE TABLE expertise ( -id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, -nome VARCHAR(50) NOT NULL -); - -CREATE TABLE teacher_expertise ( -docente_id INT NOT NULL AUTO_INCREMENT, -especialidade_id INT NOT NULL, -PRIMARY KEY (docente_id, especialidade_id), -FOREIGN KEY(docente_id) REFERENCES teacher(id), -FOREIGN KEY(especialidade_id) REFERENCES expertise(id) -); \ No newline at end of file