-
Notifications
You must be signed in to change notification settings - Fork 0
Tudo meio estranho #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| CREATE TABLE class_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| start_date DATE NOT NULL, | ||
| end_date DATE NOT NULL, | ||
| module ENUM ('0','1','2','3','4','5','6','7') DEFAULT '0' | ||
|
|
||
| ); | ||
| CREATE TABLE student_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| email VARCHAR(255) NOT NULL, | ||
| birth_date DATE NOT NULL, | ||
| class_id INT NOT NULL, | ||
| FOREIGN KEY (class_id) REFERENCES class_labenu(id) | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| email VARCHAR(255) NOT NULL, | ||
| birth_date DATE NOT NULL, | ||
| class_id INT NOT NULL, | ||
| FOREIGN KEY (class_id) REFERENCES class_labenu(id) | ||
| ); | ||
|
|
||
| CREATE TABLE student_hobbies ( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE student_hobbies_labenu( | ||
| id INT PRIMARY KEY NOt NULL, | ||
| student_id INT NOT NULL, | ||
| hobby_id INT NOT NULL, | ||
| FOREIGN KEY(student_id) REFERENCES student_labenu(id), | ||
| FOREIGN KEY(hobby_id) REFERENCES student_hobbies(id) | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_specialty( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| specialty ENUM('React', 'Redux', 'CSS', 'Testes', 'Typescript','Programação Orientada a Objetos', 'Backend') | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_speacialty_labenu ( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| teacher_id INT NOT NULL, | ||
| specialty_id INT NOT NULL, | ||
| FOREIGN KEY (teacher_id) REFERENCES teacher_labenu(id), | ||
| FOREIGN KEY (specialty_id) REFERENCES teacher_specialty(id) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,19 @@ | ||
| import { connection } from "../connection" | ||
|
|
||
| export const createClass = async ( | ||
| id: number, | ||
| name: string, | ||
| start_date: string, | ||
| end_date: string | ||
| end_date: string, | ||
| module: number | ||
| ): Promise<void> => { | ||
| await connection.raw(` | ||
| INSERT INTO class_labenu | ||
| (id, name, start_date, end_date) | ||
| VALUES ('${id}', '${name}', '${start_date}', '${end_date}') | ||
| ` | ||
|
|
||
| ) | ||
| await connection ('class_labenu').insert ({ | ||
| id: 1, | ||
| name, | ||
| start_date, | ||
| end_date, | ||
| module | ||
| }) | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| import { connection } from "../connection" | ||
|
|
||
| export const createStudent = async ( | ||
| id: number, | ||
| name: string, | ||
| email: string, | ||
| birth_date: string, | ||
| hobbies: string | ||
| ): Promise<void> => { | ||
| await connection.raw(` | ||
| INSERT INTO student_labenu | ||
| (id, name, email, birth_date, hobbies) | ||
| VALUES ('${id}', '${name}', '${email}', '${birth_date}', '${hobbies}') | ||
| ` | ||
|
|
||
| ) | ||
| } | ||
|
|
||
| name: string, | ||
| email: string, | ||
| birth_date: Date, | ||
|
|
||
| ): Promise<void> => { | ||
| await connection('student_labenu').insert({ | ||
| id: 1, | ||
| name, | ||
| email, | ||
| birth_date, | ||
| class_id: '1' | ||
|
|
||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import {connection} from "../connection" | ||
| import {Request, Response} from "express" | ||
|
|
||
|
|
||
|
|
||
| export const createTables = async(req: Request, res: Response): Promise<void> => { | ||
| try {connection.raw(` | ||
| CREATE TABLE class_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| start_date DATE NOT NULL, | ||
| end_date DATE NOT NULL, | ||
| module ENUM ('0','1','2','3','4','5','6','7') DEFAULT '0' | ||
|
|
||
| ); | ||
| CREATE TABLE student_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| email VARCHAR(255) NOT NULL, | ||
| birth_date DATE NOT NULL, | ||
|
Comment on lines
+7
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faltou o await antes do connection.raw |
||
| class_id INT NOT NULL, | ||
| FOREIGN KEY (class_id) REFERENCES class_labenu(id) | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_labenu( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL, | ||
| email VARCHAR(255) NOT NULL, | ||
| birth_date DATE NOT NULL, | ||
| class_id INT NOT NULL, | ||
| FOREIGN KEY (class_id) REFERENCES class_labenu(id) | ||
| ); | ||
|
|
||
| CREATE TABLE student_hobbies ( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| name VARCHAR(255) NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE student_hobbies_labenu( | ||
| id INT PRIMARY KEY NOt NULL, | ||
| student_id INT NOT NULL, | ||
| hobby_id INT NOT NULL, | ||
| FOREIGN KEY(student_id) REFERENCES student_labenu(id), | ||
| FOREIGN KEY(hobby_id) REFERENCES student_hobbies(id) | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_specialty( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| specialty ENUM('React', 'Redux', 'CSS', 'Testes', 'Typescript','Programação Orientada a Objetos', 'Backend') | ||
| ); | ||
|
|
||
| CREATE TABLE teacher_speacialty_labenu ( | ||
| id INT PRIMARY KEY NOT NULL, | ||
| teacher_id INT NOT NULL, | ||
| specialty_id INT NOT NULL, | ||
| FOREIGN KEY (teacher_id) REFERENCES teacher_labenu(id), | ||
| FOREIGN KEY (specialty_id) REFERENCES teacher_specialty(id) | ||
| ) | ||
| `) | ||
| res.status(200).send('Criou as tabelas') | ||
|
|
||
| } catch (error) { | ||
| res.send(error.message || error.sqlMessage) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,15 @@ import { createClass } from '../data/createClass'; | |
|
|
||
|
|
||
|
|
||
| export const addClass = async (req:Request, res:Response) => { | ||
| export const addClass = async (req:Request, res:Response): Promise<void> => { | ||
| try { | ||
|
|
||
| const {name, start_date, end_date, module} = req.body | ||
| await createClass( | ||
| req.body.id, | ||
| req.body.name, | ||
| req.body.start_date, | ||
| req.body.end_date | ||
|
|
||
| name, | ||
| start_date, | ||
|
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. È importante fazer as validações antes de tentar inserir os dados no Banco: dica: pode usar o |
||
| end_date, | ||
| module | ||
| ); | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| POST http://localhost:3003/createTable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O id precisa ser único, por enquanto podem até usar o Date.now().toString() ou o lib uuid https://www.npmjs.com/package/uuid