From a35b24cfce97b326deb55eb1a82c2dcaeed25f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 14:23:26 -0300 Subject: [PATCH 01/30] Arquivos iniciais --- .gitignore | 126 +++++++++++++++++++++++++++++++++++++ package.json | 36 +++++++++++ src/database/connection.ts | 18 ++++++ src/index.ts | 11 ++++ src/routes.ts | 5 ++ src/server.ts | 11 ++++ tsconfig.json | 71 +++++++++++++++++++++ 7 files changed, 278 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/database/connection.ts create mode 100644 src/index.ts create mode 100644 src/routes.ts create mode 100644 src/server.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66227fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,126 @@ +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ +package-lock.json + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env*.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Storybook build outputs +.out +.storybook-out +storybook-static + +# rollup.js default build output +dist/ + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# Temporary folders +tmp/ +temp/ \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..988c9cd --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "epps-labenu-system6", + "version": "1.0.0", + "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", + "main": "index.js", + "scripts": { + "dev": "ts-node-dev ./src/index.ts", + "start": "tsc && node ./build/index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/future4code/epps-labenu-system6.git" + }, + "keywords": [], + "author": "José Victor, Daniel Ratti", + "license": "ISC", + "bugs": { + "url": "https://github.com/future4code/epps-labenu-system6/issues" + }, + "homepage": "https://github.com/future4code/epps-labenu-system6#readme", + "devDependencies": { + "@types/cors": "^2.8.10", + "@types/express": "^4.17.11", + "ts-node-dev": "^1.1.6", + "typescript": "^4.2.3" + }, + "dependencies": { + "@types/knex": "^0.16.1", + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "express": "^4.17.1", + "knex": "^0.95.4", + "mysql": "^2.18.1" + } +} diff --git a/src/database/connection.ts b/src/database/connection.ts new file mode 100644 index 0000000..7133655 --- /dev/null +++ b/src/database/connection.ts @@ -0,0 +1,18 @@ +import knex from "knex"; +import dotenv from "dotenv"; + +dotenv.config(); + +export const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA, + port: 3306, + multipleStatements: true, + }, +}); + +export default connection; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..2bb0a88 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,11 @@ +import express, { Express } from "express"; +import cors from "cors"; +import { router } from "./routes"; + +const app: Express = express(); + +app.use(express.json()); +app.use(cors()); +app.use(router); + +export { app }; \ No newline at end of file diff --git a/src/routes.ts b/src/routes.ts new file mode 100644 index 0000000..09be331 --- /dev/null +++ b/src/routes.ts @@ -0,0 +1,5 @@ +import { Router } from "express"; + +const router = Router(); + +export { router }; diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..bbca370 --- /dev/null +++ b/src/server.ts @@ -0,0 +1,11 @@ +import { app } from "."; +import { AddressInfo } from "net"; + +const server = app.listen(3333, () => { + 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/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..89fe48f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./build", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} From c206fede2440f1bcc69bbcf826724baeb7939afd Mon Sep 17 00:00:00 2001 From: DanielRatti <74515266+DanielRatti@users.noreply.github.com> Date: Tue, 30 Mar 2021 14:44:11 -0300 Subject: [PATCH 02/30] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 978a24d..36f56a6 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,5 @@ As funcionalidades básicas são: → Adicionar docente na turma; → Pegar a idade de algum estudante a partir do id + +a From 6780e4179fb764211997130e72c58539759bc1fb Mon Sep 17 00:00:00 2001 From: DanielRatti <74515266+DanielRatti@users.noreply.github.com> Date: Tue, 30 Mar 2021 14:44:34 -0300 Subject: [PATCH 03/30] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 36f56a6..9e4a7d0 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,3 @@ As funcionalidades básicas são: → Pegar a idade de algum estudante a partir do id -a From c7b1e04ff32a209bf42b668e3d5f6635947e902c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 14:56:40 -0300 Subject: [PATCH 04/30] =?UTF-8?q?Mudan=C3=A7a=20nos=20arquivos=20iniciais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/controllers/ClassController.ts | 10 ++++++ src/controllers/StudentController.ts | 14 +++++++++ src/controllers/TeacherController.ts | 14 +++++++++ src/database/migrations/createTables.ts | 42 +++++++++++++++++++++++++ src/models/insertClass.ts | 7 +++++ src/models/insertStudent.ts | 7 +++++ src/models/insertTeacher.ts | 7 +++++ src/routes.ts | 11 +++++++ src/utilities/verifiers.ts | 1 + 10 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/controllers/ClassController.ts create mode 100644 src/controllers/StudentController.ts create mode 100644 src/controllers/TeacherController.ts create mode 100644 src/database/migrations/createTables.ts create mode 100644 src/models/insertClass.ts create mode 100644 src/models/insertStudent.ts create mode 100644 src/models/insertTeacher.ts create mode 100644 src/utilities/verifiers.ts diff --git a/package.json b/package.json index 988c9cd..f323fec 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "description": "Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização.", "main": "index.js", "scripts": { - "dev": "ts-node-dev ./src/index.ts", "start": "tsc && node ./build/index.js", + "table": "tsc && node ./build/database/migrations/createTables.js", + "dev": "ts-node-dev ./src/server.ts", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts new file mode 100644 index 0000000..f33780b --- /dev/null +++ b/src/controllers/ClassController.ts @@ -0,0 +1,10 @@ +import { Request, Response } from "express"; + +class ClassController { + async create(req: Request, res: Response) { + try { + } catch (error) {} + } +} + +export { ClassController }; diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts new file mode 100644 index 0000000..0799dc0 --- /dev/null +++ b/src/controllers/StudentController.ts @@ -0,0 +1,14 @@ +import { Request, Response } from "express"; + + +class StudentController { + async create(req:Request, res: Response) { + try { + + } catch (error) { + + } + } +} + +export {StudentController} \ No newline at end of file diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts new file mode 100644 index 0000000..4478f34 --- /dev/null +++ b/src/controllers/TeacherController.ts @@ -0,0 +1,14 @@ +import { Request, Response } from "express"; + + +class TeacherController { + async create(req:Request, res: Response) { + try { + + } catch (error) { + + } + } +} + +export {TeacherController} \ No newline at end of file diff --git a/src/database/migrations/createTables.ts b/src/database/migrations/createTables.ts new file mode 100644 index 0000000..fa75616 --- /dev/null +++ b/src/database/migrations/createTables.ts @@ -0,0 +1,42 @@ +import connection from "../connection"; + +const createTables = async (): Promise => { + try { + await connection.raw(` + CREATE TABLE Class( + id INT PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + start_date DATE NOT NULL, + end_date DATE NOT NULL, + module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", + type ENUM ("full-time class", "-na-night") + `); + await connection.raw(` + CREATE TABLE Teacher( + id INT PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), + class_id INT NOT NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + ); + `); + await connection.raw(` + CREATE TABLE Student( + id INT PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + hobby VARCHAR(50) NULL, + class_id INT NOT NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + `); + console.log("Tabelas criadas."); + connection.destroy(); + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; + +createTables(); diff --git a/src/models/insertClass.ts b/src/models/insertClass.ts new file mode 100644 index 0000000..dde5941 --- /dev/null +++ b/src/models/insertClass.ts @@ -0,0 +1,7 @@ +export const insertClass = async():Promise => { + try { + + } catch (error) { + + } +} \ No newline at end of file diff --git a/src/models/insertStudent.ts b/src/models/insertStudent.ts new file mode 100644 index 0000000..1fa8665 --- /dev/null +++ b/src/models/insertStudent.ts @@ -0,0 +1,7 @@ +export const insertStudent = async():Promise => { + try { + + } catch (error) { + + } +} \ No newline at end of file diff --git a/src/models/insertTeacher.ts b/src/models/insertTeacher.ts new file mode 100644 index 0000000..959149f --- /dev/null +++ b/src/models/insertTeacher.ts @@ -0,0 +1,7 @@ +export const insertTeacher = async():Promise => { + try { + + } catch (error) { + + } +} \ No newline at end of file diff --git a/src/routes.ts b/src/routes.ts index 09be331..9fb7774 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,5 +1,16 @@ import { Router } from "express"; +import { ClassController } from "./controllers/ClassController"; +import { StudentController } from "./controllers/StudentController"; +import { TeacherController } from "./controllers/TeacherController"; const router = Router(); +const classController = new ClassController(); +const studentController = new StudentController(); +const teacherController = new TeacherController(); + +router.put("/create-class", classController.create); +router.put("/create-student", studentController.create); +router.put("/create-student", teacherController.create); + export { router }; diff --git a/src/utilities/verifiers.ts b/src/utilities/verifiers.ts new file mode 100644 index 0000000..0be134c --- /dev/null +++ b/src/utilities/verifiers.ts @@ -0,0 +1 @@ +teste. \ No newline at end of file From ae0f51ea134bb643a45367a97d49ce42d65bf5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 17:05:15 -0300 Subject: [PATCH 05/30] =?UTF-8?q?Cria=C3=A7=C3=A3o=20de=20docentes=20ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/controllers/ClassController.js | 30 ++++++++++ build/controllers/ClassController.js.map | 1 + build/controllers/StudentController.js | 24 ++++++++ build/controllers/StudentController.js.map | 1 + build/controllers/TeacherController.js | 34 +++++++++++ build/controllers/TeacherController.js.map | 1 + build/database/connection.js | 22 +++++++ build/database/connection.js.map | 1 + build/database/migrations/createTables.js | 58 +++++++++++++++++++ build/database/migrations/createTables.js.map | 1 + build/index.js | 15 +++++ build/index.js.map | 1 + build/models/insertClass.js | 35 +++++++++++ build/models/insertClass.js.map | 1 + build/models/insertStudent.js | 20 +++++++ build/models/insertStudent.js.map | 1 + build/models/insertTeacher.js | 35 +++++++++++ build/models/insertTeacher.js.map | 1 + build/routes.js | 16 +++++ build/routes.js.map | 1 + build/server.js | 13 +++++ build/server.js.map | 1 + build/utilities/verifiers.js | 19 ++++++ build/utilities/verifiers.js.map | 1 + src/controllers/ClassController.ts | 9 ++- src/controllers/TeacherController.ts | 32 +++++++--- src/database/migrations/createTables.ts | 12 ++-- src/models/insertClass.ts | 13 +++-- src/models/insertTeacher.ts | 28 +++++++-- src/routes.ts | 2 +- src/utilities/verifiers.ts | 15 ++++- 31 files changed, 416 insertions(+), 28 deletions(-) create mode 100644 build/controllers/ClassController.js create mode 100644 build/controllers/ClassController.js.map create mode 100644 build/controllers/StudentController.js create mode 100644 build/controllers/StudentController.js.map create mode 100644 build/controllers/TeacherController.js create mode 100644 build/controllers/TeacherController.js.map create mode 100644 build/database/connection.js create mode 100644 build/database/connection.js.map create mode 100644 build/database/migrations/createTables.js create mode 100644 build/database/migrations/createTables.js.map create mode 100644 build/index.js create mode 100644 build/index.js.map create mode 100644 build/models/insertClass.js create mode 100644 build/models/insertClass.js.map create mode 100644 build/models/insertStudent.js create mode 100644 build/models/insertStudent.js.map create mode 100644 build/models/insertTeacher.js create mode 100644 build/models/insertTeacher.js.map create mode 100644 build/routes.js create mode 100644 build/routes.js.map create mode 100644 build/server.js create mode 100644 build/server.js.map create mode 100644 build/utilities/verifiers.js create mode 100644 build/utilities/verifiers.js.map diff --git a/build/controllers/ClassController.js b/build/controllers/ClassController.js new file mode 100644 index 0000000..6da0f49 --- /dev/null +++ b/build/controllers/ClassController.js @@ -0,0 +1,30 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ClassController = void 0; +const insertClass_1 = require("../models/insertClass"); +class ClassController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + let errorCode = 404; + try { + const { name, start_date, end_date, module, type } = req.body; + (yield insertClass_1.insertClass(name, start_date, end_date, module, type)); + res.status(201).send({ message: "Turma criada com sucesso." }); + } + catch (error) { + res.status(errorCode).send({ message: error.message }); + } + }); + } +} +exports.ClassController = ClassController; +//# sourceMappingURL=ClassController.js.map \ No newline at end of file diff --git a/build/controllers/ClassController.js.map b/build/controllers/ClassController.js.map new file mode 100644 index 0000000..487c7a7 --- /dev/null +++ b/build/controllers/ClassController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ClassController.js","sourceRoot":"","sources":["../../src/controllers/ClassController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAAoD;AAEpD,MAAM,eAAe;IACb,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBAC9D,CAAC,MAAM,yBAAW,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAW,CAAC;gBACxE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC,CAAC;aAChE;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,0CAAe"} \ No newline at end of file diff --git a/build/controllers/StudentController.js b/build/controllers/StudentController.js new file mode 100644 index 0000000..79b672d --- /dev/null +++ b/build/controllers/StudentController.js @@ -0,0 +1,24 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StudentController = void 0; +class StudentController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + try { + } + catch (error) { + } + }); + } +} +exports.StudentController = StudentController; +//# sourceMappingURL=StudentController.js.map \ No newline at end of file diff --git a/build/controllers/StudentController.js.map b/build/controllers/StudentController.js.map new file mode 100644 index 0000000..5a964f0 --- /dev/null +++ b/build/controllers/StudentController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"StudentController.js","sourceRoot":"","sources":["../../src/controllers/StudentController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,MAAM,iBAAiB;IACb,MAAM,CAAC,GAAW,EAAE,GAAa;;YACnC,IAAI;aAEH;YAAC,OAAO,KAAK,EAAE;aAEf;QACL,CAAC;KAAA;CACJ;AAEO,8CAAiB"} \ No newline at end of file diff --git a/build/controllers/TeacherController.js b/build/controllers/TeacherController.js new file mode 100644 index 0000000..294d337 --- /dev/null +++ b/build/controllers/TeacherController.js @@ -0,0 +1,34 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TeacherController = void 0; +const insertTeacher_1 = require("../models/insertTeacher"); +class TeacherController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + let errorCode = 400; + try { + const { name, email, birthdate, speciality } = req.body; + if (!name || !email || !birthdate || speciality) { + errorCode = 422; + throw new Error("Por favor preencha todas informações, nome, email, data de nascimento e especialidade."); + } + (yield insertTeacher_1.insertTeacher(name, email, birthdate, speciality)); + res.status(201).send({ message: "Docente criado com sucesso." }); + } + catch (error) { + res.status(errorCode).send({ message: error.message }); + } + }); + } +} +exports.TeacherController = TeacherController; +//# sourceMappingURL=TeacherController.js.map \ No newline at end of file diff --git a/build/controllers/TeacherController.js.map b/build/controllers/TeacherController.js.map new file mode 100644 index 0000000..c5b98a8 --- /dev/null +++ b/build/controllers/TeacherController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"TeacherController.js","sourceRoot":"","sources":["../../src/controllers/TeacherController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAwD;AAExD,MAAM,iBAAiB;IACf,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBACxD,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,UAAU,EAAE;oBAC/C,SAAS,GAAG,GAAG,CAAC;oBAChB,MAAM,IAAI,KAAK,CACb,wFAAwF,CACzF,CAAC;iBACH;gBACD,CAAC,MAAM,6BAAa,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAW,CAAC;gBACpE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC,CAAC;aAClE;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,8CAAiB"} \ No newline at end of file diff --git a/build/database/connection.js b/build/database/connection.js new file mode 100644 index 0000000..2feb930 --- /dev/null +++ b/build/database/connection.js @@ -0,0 +1,22 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.connection = void 0; +const knex_1 = __importDefault(require("knex")); +const dotenv_1 = __importDefault(require("dotenv")); +dotenv_1.default.config(); +exports.connection = knex_1.default({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA, + port: 3306, + multipleStatements: true, + }, +}); +exports.default = exports.connection; +//# sourceMappingURL=connection.js.map \ No newline at end of file diff --git a/build/database/connection.js.map b/build/database/connection.js.map new file mode 100644 index 0000000..e94c618 --- /dev/null +++ b/build/database/connection.js.map @@ -0,0 +1 @@ +{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/database/connection.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEH,QAAA,UAAU,GAAG,cAAI,CAAC;IAC7B,MAAM,EAAE,OAAO;IACf,UAAU,EAAE;QACV,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC/B,IAAI,EAAE,IAAI;QACV,kBAAkB,EAAE,IAAI;KACzB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAU,CAAC"} \ No newline at end of file diff --git a/build/database/migrations/createTables.js b/build/database/migrations/createTables.js new file mode 100644 index 0000000..9373f3e --- /dev/null +++ b/build/database/migrations/createTables.js @@ -0,0 +1,58 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const connection_1 = __importDefault(require("../connection")); +const createTables = () => __awaiter(void 0, void 0, void 0, function* () { + try { + yield connection_1.default.raw(` + CREATE TABLE Class( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + start_date DATE NOT NULL, + end_date DATE NOT NULL, + module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", + type ENUM ("full-time class", "-na-night") + ); + `); + yield connection_1.default.raw(` + CREATE TABLE Teacher( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), + class_id VARCHAR(255) NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + ); + `); + yield connection_1.default.raw(` + CREATE TABLE Student( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + hobby VARCHAR(50) NULL, + class_id VARCHAR(255) NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + ); + `); + console.log("Tabelas criadas."); + connection_1.default.destroy(); + } + catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}); +createTables(); +//# sourceMappingURL=createTables.js.map \ No newline at end of file diff --git a/build/database/migrations/createTables.js.map b/build/database/migrations/createTables.js.map new file mode 100644 index 0000000..ff9259c --- /dev/null +++ b/build/database/migrations/createTables.js.map @@ -0,0 +1 @@ +{"version":3,"file":"createTables.js","sourceRoot":"","sources":["../../../src/database/migrations/createTables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuC;AAEvC,MAAM,YAAY,GAAG,GAAwB,EAAE;IAC7C,IAAI;QACF,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;OASlB,CAAC,CAAC;QACL,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;;OAUlB,CAAC,CAAC;QACL,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;;SAUhB,CAAC,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,oBAAU,CAAC,OAAO,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AAEF,YAAY,EAAE,CAAC"} \ No newline at end of file diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..82c3c33 --- /dev/null +++ b/build/index.js @@ -0,0 +1,15 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.app = void 0; +const express_1 = __importDefault(require("express")); +const cors_1 = __importDefault(require("cors")); +const routes_1 = require("./routes"); +const app = express_1.default(); +exports.app = app; +app.use(express_1.default.json()); +app.use(cors_1.default()); +app.use(routes_1.router); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map new file mode 100644 index 0000000..17a3742 --- /dev/null +++ b/build/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,qCAAkC;AAElC,MAAM,GAAG,GAAY,iBAAO,EAAE,CAAC;AAMtB,kBAAG;AAJZ,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,cAAI,EAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,eAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/models/insertClass.js b/build/models/insertClass.js new file mode 100644 index 0000000..a8aaeb7 --- /dev/null +++ b/build/models/insertClass.js @@ -0,0 +1,35 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertClass = void 0; +const connection_1 = __importDefault(require("../database/connection")); +const insertClass = (name, start_date, end_date, module, type) => __awaiter(void 0, void 0, void 0, function* () { + try { + yield connection_1.default + .insert({ + id: Date.now(), + name, + start_date, + end_date, + module, + type, + }) + .into("Class"); + } + catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}); +exports.insertClass = insertClass; +//# sourceMappingURL=insertClass.js.map \ No newline at end of file diff --git a/build/models/insertClass.js.map b/build/models/insertClass.js.map new file mode 100644 index 0000000..93ce18d --- /dev/null +++ b/build/models/insertClass.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertClass.js","sourceRoot":"","sources":["../../src/models/insertClass.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wEAAgD;AAEzC,MAAM,WAAW,GAAG,CACzB,IAAY,EACZ,UAAkB,EAClB,QAAgB,EAChB,MAAc,EACd,IAAY,EACE,EAAE;IAChB,IAAI;QACF,MAAM,oBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI;YACJ,UAAU;YACV,QAAQ;YACR,MAAM;YACN,IAAI;SACL,CAAC;aACD,IAAI,CAAC,OAAO,CAAC,CAAC;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AArBW,QAAA,WAAW,eAqBtB"} \ No newline at end of file diff --git a/build/models/insertStudent.js b/build/models/insertStudent.js new file mode 100644 index 0000000..ad4679a --- /dev/null +++ b/build/models/insertStudent.js @@ -0,0 +1,20 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertStudent = void 0; +const insertStudent = () => __awaiter(void 0, void 0, void 0, function* () { + try { + } + catch (error) { + } +}); +exports.insertStudent = insertStudent; +//# sourceMappingURL=insertStudent.js.map \ No newline at end of file diff --git a/build/models/insertStudent.js.map b/build/models/insertStudent.js.map new file mode 100644 index 0000000..a9dce03 --- /dev/null +++ b/build/models/insertStudent.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertStudent.js","sourceRoot":"","sources":["../../src/models/insertStudent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,aAAa,GAAG,GAAsB,EAAE;IACjD,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,aAAa,iBAMzB"} \ No newline at end of file diff --git a/build/models/insertTeacher.js b/build/models/insertTeacher.js new file mode 100644 index 0000000..fa5c909 --- /dev/null +++ b/build/models/insertTeacher.js @@ -0,0 +1,35 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertTeacher = void 0; +const connection_1 = __importDefault(require("../database/connection")); +const insertTeacher = (name, email, birthdate, speciality) => __awaiter(void 0, void 0, void 0, function* () { + try { + yield connection_1.default + .insert({ + id: Date.now(), + name, + email, + birthdate, + speciality, + }) + .into("Teacher"); + } + catch (error) { + console.log(error.message || error.sqlMessage); + throw new Error(error.message || error.sqlMessage); + } +}); +exports.insertTeacher = insertTeacher; +//# sourceMappingURL=insertTeacher.js.map \ No newline at end of file diff --git a/build/models/insertTeacher.js.map b/build/models/insertTeacher.js.map new file mode 100644 index 0000000..3fb1f92 --- /dev/null +++ b/build/models/insertTeacher.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertTeacher.js","sourceRoot":"","sources":["../../src/models/insertTeacher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wEAAgD;AAEzC,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,KAAa,EACb,SAAiB,EACjB,UAAkB,EACJ,EAAE;IAChB,IAAI;QACF,MAAM,oBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI;YACJ,KAAK;YACL,SAAS;YACT,UAAU;SACX,CAAC;aACD,IAAI,CAAC,SAAS,CAAC,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;QAC9C,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AApBW,QAAA,aAAa,iBAoBxB"} \ No newline at end of file diff --git a/build/routes.js b/build/routes.js new file mode 100644 index 0000000..e41f728 --- /dev/null +++ b/build/routes.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const ClassController_1 = require("./controllers/ClassController"); +const StudentController_1 = require("./controllers/StudentController"); +const TeacherController_1 = require("./controllers/TeacherController"); +const router = express_1.Router(); +exports.router = router; +const classController = new ClassController_1.ClassController(); +const studentController = new StudentController_1.StudentController(); +const teacherController = new TeacherController_1.TeacherController(); +router.put("/create-class", classController.create); +router.put("/create-student", studentController.create); +router.put("/create-teacher", teacherController.create); +//# sourceMappingURL=routes.js.map \ No newline at end of file diff --git a/build/routes.js.map b/build/routes.js.map new file mode 100644 index 0000000..e1dae70 --- /dev/null +++ b/build/routes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mEAAgE;AAChE,uEAAoE;AACpE,uEAAoE;AAEpE,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAUf,wBAAM;AARf,MAAM,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAClD,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAElD,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/server.js b/build/server.js new file mode 100644 index 0000000..7ed959d --- /dev/null +++ b/build/server.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const _1 = require("."); +const server = _1.app.listen(3333, () => { + if (server) { + const address = server.address(); + console.log(`Server is running in http://localhost:${address.port}`); + } + else { + console.error(`Failure upon starting server.`); + } +}); +//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/build/server.js.map b/build/server.js.map new file mode 100644 index 0000000..11dca8b --- /dev/null +++ b/build/server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AAGxB,MAAM,MAAM,GAAG,MAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACnC,IAAI,MAAM,EAAE;QACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,yCAAyC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACtE;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAChD;AACH,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/build/utilities/verifiers.js b/build/utilities/verifiers.js new file mode 100644 index 0000000..42242a8 --- /dev/null +++ b/build/utilities/verifiers.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.checkDate = exports.formatDate = void 0; +const formatDate = (date) => { + const [day, month, year] = date.split("/"); + return `${year}-${month}-${day}`; +}; +exports.formatDate = formatDate; +const checkDate = (date) => { + const useBar = date.includes("/"); + if (useBar) { + return true; + } + else { + return false; + } +}; +exports.checkDate = checkDate; +//# sourceMappingURL=verifiers.js.map \ No newline at end of file diff --git a/build/utilities/verifiers.js.map b/build/utilities/verifiers.js.map new file mode 100644 index 0000000..19194fb --- /dev/null +++ b/build/utilities/verifiers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"verifiers.js","sourceRoot":"","sources":["../../src/utilities/verifiers.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IACjD,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,MAAM,EAAE;QACV,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB"} \ No newline at end of file diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts index f33780b..6aa679d 100644 --- a/src/controllers/ClassController.ts +++ b/src/controllers/ClassController.ts @@ -1,9 +1,16 @@ import { Request, Response } from "express"; +import { insertClass } from "../models/insertClass"; class ClassController { async create(req: Request, res: Response) { + let errorCode: number = 404; try { - } catch (error) {} + const { name, start_date, end_date, module, type } = req.body; + (await insertClass(name, start_date, end_date, module, type)) as string; + res.status(201).send({ message: "Turma criada com sucesso." }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } } } diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index 4478f34..12b715d 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -1,14 +1,30 @@ import { Request, Response } from "express"; - +import { insertTeacher } from "../models/insertTeacher"; +import { checkDate, formatDate } from "../utilities/verifiers"; class TeacherController { - async create(req:Request, res: Response) { - try { - - } catch (error) { - - } + async create(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { name, email, birthdate, speciality } = req.body; + const checkingDate = checkDate(birthdate); + if (!name || !email || !birthdate || !speciality) { + errorCode = 422; + throw new Error( + "Por favor preencha todas as informações, nome, email, data de nascimento e especialidade." + ); + } + if (!checkingDate) { + errorCode = 406; + throw new Error("Coloque uma data formato DD/MM/YYYY"); + } + const formatingDate = formatDate(birthdate); + await insertTeacher(name, email, formatingDate, speciality); + res.status(201).send({ message: "Docente criado com sucesso." }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); } + } } -export {TeacherController} \ No newline at end of file +export { TeacherController }; diff --git a/src/database/migrations/createTables.ts b/src/database/migrations/createTables.ts index fa75616..94dd32d 100644 --- a/src/database/migrations/createTables.ts +++ b/src/database/migrations/createTables.ts @@ -4,33 +4,35 @@ const createTables = async (): Promise => { try { await connection.raw(` CREATE TABLE Class( - id INT PRIMARY KEY NOT NULL, + id VARCHAR(255) PRIMARY KEY NOT NULL, name VARCHAR(50) NOT NULL, start_date DATE NOT NULL, end_date DATE NOT NULL, module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", type ENUM ("full-time class", "-na-night") + ); `); await connection.raw(` CREATE TABLE Teacher( - id INT PRIMARY KEY NOT NULL, + id VARCHAR(255) PRIMARY KEY NOT NULL, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL UNIQUE, birthdate DATE NOT NULL, speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), - class_id INT NOT NULL, + class_id VARCHAR(255) NULL, FOREIGN KEY (class_id) REFERENCES Class(id) ); `); await connection.raw(` CREATE TABLE Student( - id INT PRIMARY KEY NOT NULL, + id VARCHAR(255) PRIMARY KEY NOT NULL, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL UNIQUE, birthdate DATE NOT NULL, hobby VARCHAR(50) NULL, - class_id INT NOT NULL, + class_id VARCHAR(255) NULL, FOREIGN KEY (class_id) REFERENCES Class(id) + ); `); console.log("Tabelas criadas."); connection.destroy(); diff --git a/src/models/insertClass.ts b/src/models/insertClass.ts index dde5941..05c4495 100644 --- a/src/models/insertClass.ts +++ b/src/models/insertClass.ts @@ -1,7 +1,8 @@ -export const insertClass = async():Promise => { - try { +import connection from "../database/connection"; - } catch (error) { - - } -} \ No newline at end of file +export const insertClass = async (): Promise => { + try { + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/models/insertTeacher.ts b/src/models/insertTeacher.ts index 959149f..4645d48 100644 --- a/src/models/insertTeacher.ts +++ b/src/models/insertTeacher.ts @@ -1,7 +1,23 @@ -export const insertTeacher = async():Promise => { - try { +import connection from "../database/connection"; - } catch (error) { - - } -} \ No newline at end of file +export const insertTeacher = async ( + name: string, + email: string, + birthdate: string, + speciality: string +): Promise => { + try { + await connection + .insert({ + id: Date.now(), + name, + email, + birthdate, + speciality, + }) + .into("Teacher"); + } catch (error) { + console.log(error.message || error.sqlMessage) + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 9fb7774..37bedef 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -11,6 +11,6 @@ const teacherController = new TeacherController(); router.put("/create-class", classController.create); router.put("/create-student", studentController.create); -router.put("/create-student", teacherController.create); +router.put("/create-teacher", teacherController.create); export { router }; diff --git a/src/utilities/verifiers.ts b/src/utilities/verifiers.ts index 0be134c..697472c 100644 --- a/src/utilities/verifiers.ts +++ b/src/utilities/verifiers.ts @@ -1 +1,14 @@ -teste. \ No newline at end of file +export const formatDate = (date: string): string => { + const [day, month, year] = date.split("/"); + return `${year}-${month}-${day}`; +}; + +export const checkDate = (date: string): boolean => { + const useBar = date.includes("/"); + + if (useBar) { + return true; + } else { + return false; + } +}; From 2057019d4aa157e7477d23208decc628d4bdd338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 17:09:51 -0300 Subject: [PATCH 06/30] git ignore, build folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 66227fd..33d50de 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ build/Release node_modules/ jspm_packages/ package-lock.json +build # TypeScript v1 declaration files typings/ From e1ee63c65ab4b775796c86f7e396ce465aef5b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 17:13:15 -0300 Subject: [PATCH 07/30] gitignore working now --- .gitignore | 2 +- build/controllers/ClassController.js | 30 ---------- build/controllers/ClassController.js.map | 1 - build/controllers/StudentController.js | 24 -------- build/controllers/StudentController.js.map | 1 - build/controllers/TeacherController.js | 34 ----------- build/controllers/TeacherController.js.map | 1 - build/database/connection.js | 22 ------- build/database/connection.js.map | 1 - build/database/migrations/createTables.js | 58 ------------------- build/database/migrations/createTables.js.map | 1 - build/index.js | 15 ----- build/index.js.map | 1 - build/models/insertClass.js | 35 ----------- build/models/insertClass.js.map | 1 - build/models/insertStudent.js | 20 ------- build/models/insertStudent.js.map | 1 - build/models/insertTeacher.js | 35 ----------- build/models/insertTeacher.js.map | 1 - build/routes.js | 16 ----- build/routes.js.map | 1 - build/server.js | 13 ----- build/server.js.map | 1 - build/utilities/verifiers.js | 19 ------ build/utilities/verifiers.js.map | 1 - 25 files changed, 1 insertion(+), 334 deletions(-) delete mode 100644 build/controllers/ClassController.js delete mode 100644 build/controllers/ClassController.js.map delete mode 100644 build/controllers/StudentController.js delete mode 100644 build/controllers/StudentController.js.map delete mode 100644 build/controllers/TeacherController.js delete mode 100644 build/controllers/TeacherController.js.map delete mode 100644 build/database/connection.js delete mode 100644 build/database/connection.js.map delete mode 100644 build/database/migrations/createTables.js delete mode 100644 build/database/migrations/createTables.js.map delete mode 100644 build/index.js delete mode 100644 build/index.js.map delete mode 100644 build/models/insertClass.js delete mode 100644 build/models/insertClass.js.map delete mode 100644 build/models/insertStudent.js delete mode 100644 build/models/insertStudent.js.map delete mode 100644 build/models/insertTeacher.js delete mode 100644 build/models/insertTeacher.js.map delete mode 100644 build/routes.js delete mode 100644 build/routes.js.map delete mode 100644 build/server.js delete mode 100644 build/server.js.map delete mode 100644 build/utilities/verifiers.js delete mode 100644 build/utilities/verifiers.js.map diff --git a/.gitignore b/.gitignore index 33d50de..3f8d421 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ build/Release node_modules/ jspm_packages/ package-lock.json -build +build/ # TypeScript v1 declaration files typings/ diff --git a/build/controllers/ClassController.js b/build/controllers/ClassController.js deleted file mode 100644 index 6da0f49..0000000 --- a/build/controllers/ClassController.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ClassController = void 0; -const insertClass_1 = require("../models/insertClass"); -class ClassController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - let errorCode = 404; - try { - const { name, start_date, end_date, module, type } = req.body; - (yield insertClass_1.insertClass(name, start_date, end_date, module, type)); - res.status(201).send({ message: "Turma criada com sucesso." }); - } - catch (error) { - res.status(errorCode).send({ message: error.message }); - } - }); - } -} -exports.ClassController = ClassController; -//# sourceMappingURL=ClassController.js.map \ No newline at end of file diff --git a/build/controllers/ClassController.js.map b/build/controllers/ClassController.js.map deleted file mode 100644 index 487c7a7..0000000 --- a/build/controllers/ClassController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ClassController.js","sourceRoot":"","sources":["../../src/controllers/ClassController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAAoD;AAEpD,MAAM,eAAe;IACb,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBAC9D,CAAC,MAAM,yBAAW,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAW,CAAC;gBACxE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC,CAAC;aAChE;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,0CAAe"} \ No newline at end of file diff --git a/build/controllers/StudentController.js b/build/controllers/StudentController.js deleted file mode 100644 index 79b672d..0000000 --- a/build/controllers/StudentController.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.StudentController = void 0; -class StudentController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - try { - } - catch (error) { - } - }); - } -} -exports.StudentController = StudentController; -//# sourceMappingURL=StudentController.js.map \ No newline at end of file diff --git a/build/controllers/StudentController.js.map b/build/controllers/StudentController.js.map deleted file mode 100644 index 5a964f0..0000000 --- a/build/controllers/StudentController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"StudentController.js","sourceRoot":"","sources":["../../src/controllers/StudentController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,MAAM,iBAAiB;IACb,MAAM,CAAC,GAAW,EAAE,GAAa;;YACnC,IAAI;aAEH;YAAC,OAAO,KAAK,EAAE;aAEf;QACL,CAAC;KAAA;CACJ;AAEO,8CAAiB"} \ No newline at end of file diff --git a/build/controllers/TeacherController.js b/build/controllers/TeacherController.js deleted file mode 100644 index 294d337..0000000 --- a/build/controllers/TeacherController.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TeacherController = void 0; -const insertTeacher_1 = require("../models/insertTeacher"); -class TeacherController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - let errorCode = 400; - try { - const { name, email, birthdate, speciality } = req.body; - if (!name || !email || !birthdate || speciality) { - errorCode = 422; - throw new Error("Por favor preencha todas informações, nome, email, data de nascimento e especialidade."); - } - (yield insertTeacher_1.insertTeacher(name, email, birthdate, speciality)); - res.status(201).send({ message: "Docente criado com sucesso." }); - } - catch (error) { - res.status(errorCode).send({ message: error.message }); - } - }); - } -} -exports.TeacherController = TeacherController; -//# sourceMappingURL=TeacherController.js.map \ No newline at end of file diff --git a/build/controllers/TeacherController.js.map b/build/controllers/TeacherController.js.map deleted file mode 100644 index c5b98a8..0000000 --- a/build/controllers/TeacherController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"TeacherController.js","sourceRoot":"","sources":["../../src/controllers/TeacherController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAwD;AAExD,MAAM,iBAAiB;IACf,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBACxD,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,UAAU,EAAE;oBAC/C,SAAS,GAAG,GAAG,CAAC;oBAChB,MAAM,IAAI,KAAK,CACb,wFAAwF,CACzF,CAAC;iBACH;gBACD,CAAC,MAAM,6BAAa,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAW,CAAC;gBACpE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC,CAAC;aAClE;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,8CAAiB"} \ No newline at end of file diff --git a/build/database/connection.js b/build/database/connection.js deleted file mode 100644 index 2feb930..0000000 --- a/build/database/connection.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.connection = void 0; -const knex_1 = __importDefault(require("knex")); -const dotenv_1 = __importDefault(require("dotenv")); -dotenv_1.default.config(); -exports.connection = knex_1.default({ - client: "mysql", - connection: { - host: process.env.DB_HOST, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_SCHEMA, - port: 3306, - multipleStatements: true, - }, -}); -exports.default = exports.connection; -//# sourceMappingURL=connection.js.map \ No newline at end of file diff --git a/build/database/connection.js.map b/build/database/connection.js.map deleted file mode 100644 index e94c618..0000000 --- a/build/database/connection.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/database/connection.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEH,QAAA,UAAU,GAAG,cAAI,CAAC;IAC7B,MAAM,EAAE,OAAO;IACf,UAAU,EAAE;QACV,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC/B,IAAI,EAAE,IAAI;QACV,kBAAkB,EAAE,IAAI;KACzB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAU,CAAC"} \ No newline at end of file diff --git a/build/database/migrations/createTables.js b/build/database/migrations/createTables.js deleted file mode 100644 index 9373f3e..0000000 --- a/build/database/migrations/createTables.js +++ /dev/null @@ -1,58 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const connection_1 = __importDefault(require("../connection")); -const createTables = () => __awaiter(void 0, void 0, void 0, function* () { - try { - yield connection_1.default.raw(` - CREATE TABLE Class( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - start_date DATE NOT NULL, - end_date DATE NOT NULL, - module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", - type ENUM ("full-time class", "-na-night") - ); - `); - yield connection_1.default.raw(` - CREATE TABLE Teacher( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL UNIQUE, - birthdate DATE NOT NULL, - speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), - class_id VARCHAR(255) NULL, - FOREIGN KEY (class_id) REFERENCES Class(id) - ); - `); - yield connection_1.default.raw(` - CREATE TABLE Student( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL UNIQUE, - birthdate DATE NOT NULL, - hobby VARCHAR(50) NULL, - class_id VARCHAR(255) NULL, - FOREIGN KEY (class_id) REFERENCES Class(id) - ); - `); - console.log("Tabelas criadas."); - connection_1.default.destroy(); - } - catch (error) { - throw new Error(error.message || error.sqlMessage); - } -}); -createTables(); -//# sourceMappingURL=createTables.js.map \ No newline at end of file diff --git a/build/database/migrations/createTables.js.map b/build/database/migrations/createTables.js.map deleted file mode 100644 index ff9259c..0000000 --- a/build/database/migrations/createTables.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createTables.js","sourceRoot":"","sources":["../../../src/database/migrations/createTables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuC;AAEvC,MAAM,YAAY,GAAG,GAAwB,EAAE;IAC7C,IAAI;QACF,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;OASlB,CAAC,CAAC;QACL,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;;OAUlB,CAAC,CAAC;QACL,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;;;SAUhB,CAAC,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,oBAAU,CAAC,OAAO,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AAEF,YAAY,EAAE,CAAC"} \ No newline at end of file diff --git a/build/index.js b/build/index.js deleted file mode 100644 index 82c3c33..0000000 --- a/build/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.app = void 0; -const express_1 = __importDefault(require("express")); -const cors_1 = __importDefault(require("cors")); -const routes_1 = require("./routes"); -const app = express_1.default(); -exports.app = app; -app.use(express_1.default.json()); -app.use(cors_1.default()); -app.use(routes_1.router); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map deleted file mode 100644 index 17a3742..0000000 --- a/build/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,qCAAkC;AAElC,MAAM,GAAG,GAAY,iBAAO,EAAE,CAAC;AAMtB,kBAAG;AAJZ,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,cAAI,EAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,eAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/models/insertClass.js b/build/models/insertClass.js deleted file mode 100644 index a8aaeb7..0000000 --- a/build/models/insertClass.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertClass = void 0; -const connection_1 = __importDefault(require("../database/connection")); -const insertClass = (name, start_date, end_date, module, type) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield connection_1.default - .insert({ - id: Date.now(), - name, - start_date, - end_date, - module, - type, - }) - .into("Class"); - } - catch (error) { - throw new Error(error.message || error.sqlMessage); - } -}); -exports.insertClass = insertClass; -//# sourceMappingURL=insertClass.js.map \ No newline at end of file diff --git a/build/models/insertClass.js.map b/build/models/insertClass.js.map deleted file mode 100644 index 93ce18d..0000000 --- a/build/models/insertClass.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertClass.js","sourceRoot":"","sources":["../../src/models/insertClass.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wEAAgD;AAEzC,MAAM,WAAW,GAAG,CACzB,IAAY,EACZ,UAAkB,EAClB,QAAgB,EAChB,MAAc,EACd,IAAY,EACE,EAAE;IAChB,IAAI;QACF,MAAM,oBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI;YACJ,UAAU;YACV,QAAQ;YACR,MAAM;YACN,IAAI;SACL,CAAC;aACD,IAAI,CAAC,OAAO,CAAC,CAAC;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AArBW,QAAA,WAAW,eAqBtB"} \ No newline at end of file diff --git a/build/models/insertStudent.js b/build/models/insertStudent.js deleted file mode 100644 index ad4679a..0000000 --- a/build/models/insertStudent.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertStudent = void 0; -const insertStudent = () => __awaiter(void 0, void 0, void 0, function* () { - try { - } - catch (error) { - } -}); -exports.insertStudent = insertStudent; -//# sourceMappingURL=insertStudent.js.map \ No newline at end of file diff --git a/build/models/insertStudent.js.map b/build/models/insertStudent.js.map deleted file mode 100644 index a9dce03..0000000 --- a/build/models/insertStudent.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertStudent.js","sourceRoot":"","sources":["../../src/models/insertStudent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,aAAa,GAAG,GAAsB,EAAE;IACjD,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,aAAa,iBAMzB"} \ No newline at end of file diff --git a/build/models/insertTeacher.js b/build/models/insertTeacher.js deleted file mode 100644 index fa5c909..0000000 --- a/build/models/insertTeacher.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertTeacher = void 0; -const connection_1 = __importDefault(require("../database/connection")); -const insertTeacher = (name, email, birthdate, speciality) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield connection_1.default - .insert({ - id: Date.now(), - name, - email, - birthdate, - speciality, - }) - .into("Teacher"); - } - catch (error) { - console.log(error.message || error.sqlMessage); - throw new Error(error.message || error.sqlMessage); - } -}); -exports.insertTeacher = insertTeacher; -//# sourceMappingURL=insertTeacher.js.map \ No newline at end of file diff --git a/build/models/insertTeacher.js.map b/build/models/insertTeacher.js.map deleted file mode 100644 index 3fb1f92..0000000 --- a/build/models/insertTeacher.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertTeacher.js","sourceRoot":"","sources":["../../src/models/insertTeacher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wEAAgD;AAEzC,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,KAAa,EACb,SAAiB,EACjB,UAAkB,EACJ,EAAE;IAChB,IAAI;QACF,MAAM,oBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI;YACJ,KAAK;YACL,SAAS;YACT,UAAU;SACX,CAAC;aACD,IAAI,CAAC,SAAS,CAAC,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;QAC9C,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AApBW,QAAA,aAAa,iBAoBxB"} \ No newline at end of file diff --git a/build/routes.js b/build/routes.js deleted file mode 100644 index e41f728..0000000 --- a/build/routes.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.router = void 0; -const express_1 = require("express"); -const ClassController_1 = require("./controllers/ClassController"); -const StudentController_1 = require("./controllers/StudentController"); -const TeacherController_1 = require("./controllers/TeacherController"); -const router = express_1.Router(); -exports.router = router; -const classController = new ClassController_1.ClassController(); -const studentController = new StudentController_1.StudentController(); -const teacherController = new TeacherController_1.TeacherController(); -router.put("/create-class", classController.create); -router.put("/create-student", studentController.create); -router.put("/create-teacher", teacherController.create); -//# sourceMappingURL=routes.js.map \ No newline at end of file diff --git a/build/routes.js.map b/build/routes.js.map deleted file mode 100644 index e1dae70..0000000 --- a/build/routes.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mEAAgE;AAChE,uEAAoE;AACpE,uEAAoE;AAEpE,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAUf,wBAAM;AARf,MAAM,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAClD,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAElD,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/server.js b/build/server.js deleted file mode 100644 index 7ed959d..0000000 --- a/build/server.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _1 = require("."); -const server = _1.app.listen(3333, () => { - if (server) { - const address = server.address(); - console.log(`Server is running in http://localhost:${address.port}`); - } - else { - console.error(`Failure upon starting server.`); - } -}); -//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/build/server.js.map b/build/server.js.map deleted file mode 100644 index 11dca8b..0000000 --- a/build/server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AAGxB,MAAM,MAAM,GAAG,MAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACnC,IAAI,MAAM,EAAE;QACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,yCAAyC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACtE;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAChD;AACH,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/build/utilities/verifiers.js b/build/utilities/verifiers.js deleted file mode 100644 index 42242a8..0000000 --- a/build/utilities/verifiers.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkDate = exports.formatDate = void 0; -const formatDate = (date) => { - const [day, month, year] = date.split("/"); - return `${year}-${month}-${day}`; -}; -exports.formatDate = formatDate; -const checkDate = (date) => { - const useBar = date.includes("/"); - if (useBar) { - return true; - } - else { - return false; - } -}; -exports.checkDate = checkDate; -//# sourceMappingURL=verifiers.js.map \ No newline at end of file diff --git a/build/utilities/verifiers.js.map b/build/utilities/verifiers.js.map deleted file mode 100644 index 19194fb..0000000 --- a/build/utilities/verifiers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"verifiers.js","sourceRoot":"","sources":["../../src/utilities/verifiers.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IACjD,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,MAAM,EAAE;QACV,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB"} \ No newline at end of file From 98f0fdb40fda9224f657e0f75ef1efad88d8c803 Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Tue, 30 Mar 2021 17:15:42 -0300 Subject: [PATCH 08/30] =?UTF-8?q?Cria=C3=A7=C3=A3o=20students?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/controllers/ClassController.js | 23 ++++++++ build/controllers/ClassController.js.map | 1 + build/controllers/StudentController.js | 36 +++++++++++++ build/controllers/StudentController.js.map | 1 + build/controllers/TeacherController.js | 24 +++++++++ build/controllers/TeacherController.js.map | 1 + build/database/connection.js | 22 ++++++++ build/database/connection.js.map | 1 + build/database/migrations/createTables.js | 53 +++++++++++++++++++ build/database/migrations/createTables.js.map | 1 + build/index.js | 15 ++++++ build/index.js.map | 1 + build/models/insertClass.js | 20 +++++++ build/models/insertClass.js.map | 1 + build/models/insertStudent.js | 31 +++++++++++ build/models/insertStudent.js.map | 1 + build/models/insertTeacher.js | 20 +++++++ build/models/insertTeacher.js.map | 1 + build/routes.js | 16 ++++++ build/routes.js.map | 1 + build/server.js | 13 +++++ build/server.js.map | 1 + build/utilities/verifiers.js | 19 +++++++ build/utilities/verifiers.js.map | 1 + src/controllers/StudentController.ts | 35 +++++++++--- src/database/migrations/createTables.ts | 49 ++++++++--------- src/models/insertStudent.ts | 28 +++++++--- src/utilities/verifiers.ts | 16 +++++- 28 files changed, 393 insertions(+), 39 deletions(-) create mode 100644 build/controllers/ClassController.js create mode 100644 build/controllers/ClassController.js.map create mode 100644 build/controllers/StudentController.js create mode 100644 build/controllers/StudentController.js.map create mode 100644 build/controllers/TeacherController.js create mode 100644 build/controllers/TeacherController.js.map create mode 100644 build/database/connection.js create mode 100644 build/database/connection.js.map create mode 100644 build/database/migrations/createTables.js create mode 100644 build/database/migrations/createTables.js.map create mode 100644 build/index.js create mode 100644 build/index.js.map create mode 100644 build/models/insertClass.js create mode 100644 build/models/insertClass.js.map create mode 100644 build/models/insertStudent.js create mode 100644 build/models/insertStudent.js.map create mode 100644 build/models/insertTeacher.js create mode 100644 build/models/insertTeacher.js.map create mode 100644 build/routes.js create mode 100644 build/routes.js.map create mode 100644 build/server.js create mode 100644 build/server.js.map create mode 100644 build/utilities/verifiers.js create mode 100644 build/utilities/verifiers.js.map diff --git a/build/controllers/ClassController.js b/build/controllers/ClassController.js new file mode 100644 index 0000000..c0f8547 --- /dev/null +++ b/build/controllers/ClassController.js @@ -0,0 +1,23 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ClassController = void 0; +class ClassController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + try { + } + catch (error) { } + }); + } +} +exports.ClassController = ClassController; +//# sourceMappingURL=ClassController.js.map \ No newline at end of file diff --git a/build/controllers/ClassController.js.map b/build/controllers/ClassController.js.map new file mode 100644 index 0000000..673cf02 --- /dev/null +++ b/build/controllers/ClassController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ClassController.js","sourceRoot":"","sources":["../../src/controllers/ClassController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,MAAM,eAAe;IACb,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI;aACH;YAAC,OAAO,KAAK,EAAE,GAAE;QACpB,CAAC;KAAA;CACF;AAEQ,0CAAe"} \ No newline at end of file diff --git a/build/controllers/StudentController.js b/build/controllers/StudentController.js new file mode 100644 index 0000000..1d9ee06 --- /dev/null +++ b/build/controllers/StudentController.js @@ -0,0 +1,36 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StudentController = void 0; +const insertStudent_1 = require("./../models/insertStudent"); +class StudentController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + let errorCode = 400; + try { + const { name, email, birthdate, hobby } = req.body; + if (!name || !email || !birthdate || !hobby) { + errorCode = 422; + throw new Error("Preencha todas as informações necessarias para adicionar um estudante !"); + } + yield insertStudent_1.insertStudent(name, email, birthdate, hobby); + res.status(201).send({ + message: `Estudante ${name} adicionado a turma !`, + }); + } + catch (error) { + res.status(errorCode).send({ message: error.message }); + } + }); + } +} +exports.StudentController = StudentController; +//# sourceMappingURL=StudentController.js.map \ No newline at end of file diff --git a/build/controllers/StudentController.js.map b/build/controllers/StudentController.js.map new file mode 100644 index 0000000..d0c237d --- /dev/null +++ b/build/controllers/StudentController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"StudentController.js","sourceRoot":"","sources":["../../src/controllers/StudentController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAA0D;AAG1D,MAAM,iBAAiB;IACf,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBACnD,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;oBAC3C,SAAS,GAAG,GAAG,CAAC;oBAChB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;iBACH;gBACD,MAAM,6BAAa,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,aAAa,IAAI,uBAAuB;iBAClD,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,8CAAiB"} \ No newline at end of file diff --git a/build/controllers/TeacherController.js b/build/controllers/TeacherController.js new file mode 100644 index 0000000..20b79b1 --- /dev/null +++ b/build/controllers/TeacherController.js @@ -0,0 +1,24 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TeacherController = void 0; +class TeacherController { + create(req, res) { + return __awaiter(this, void 0, void 0, function* () { + try { + } + catch (error) { + } + }); + } +} +exports.TeacherController = TeacherController; +//# sourceMappingURL=TeacherController.js.map \ No newline at end of file diff --git a/build/controllers/TeacherController.js.map b/build/controllers/TeacherController.js.map new file mode 100644 index 0000000..8188e02 --- /dev/null +++ b/build/controllers/TeacherController.js.map @@ -0,0 +1 @@ +{"version":3,"file":"TeacherController.js","sourceRoot":"","sources":["../../src/controllers/TeacherController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,MAAM,iBAAiB;IACb,MAAM,CAAC,GAAW,EAAE,GAAa;;YACnC,IAAI;aAEH;YAAC,OAAO,KAAK,EAAE;aAEf;QACL,CAAC;KAAA;CACJ;AAEO,8CAAiB"} \ No newline at end of file diff --git a/build/database/connection.js b/build/database/connection.js new file mode 100644 index 0000000..2feb930 --- /dev/null +++ b/build/database/connection.js @@ -0,0 +1,22 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.connection = void 0; +const knex_1 = __importDefault(require("knex")); +const dotenv_1 = __importDefault(require("dotenv")); +dotenv_1.default.config(); +exports.connection = knex_1.default({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA, + port: 3306, + multipleStatements: true, + }, +}); +exports.default = exports.connection; +//# sourceMappingURL=connection.js.map \ No newline at end of file diff --git a/build/database/connection.js.map b/build/database/connection.js.map new file mode 100644 index 0000000..e94c618 --- /dev/null +++ b/build/database/connection.js.map @@ -0,0 +1 @@ +{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/database/connection.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEH,QAAA,UAAU,GAAG,cAAI,CAAC;IAC7B,MAAM,EAAE,OAAO;IACf,UAAU,EAAE;QACV,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC/B,IAAI,EAAE,IAAI;QACV,kBAAkB,EAAE,IAAI;KACzB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAU,CAAC"} \ No newline at end of file diff --git a/build/database/migrations/createTables.js b/build/database/migrations/createTables.js new file mode 100644 index 0000000..08ad60a --- /dev/null +++ b/build/database/migrations/createTables.js @@ -0,0 +1,53 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const connection_1 = __importDefault(require("../connection")); +const createTables = () => __awaiter(void 0, void 0, void 0, function* () { + try { + yield connection_1.default.raw(` + CREATE TABLE Class( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + start_date DATE NOT NULL, + end_date DATE NOT NULL, + module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", + type ENUM ("full-time class", "-na-night") + );`); + yield connection_1.default.raw(`CREATE TABLE Teacher( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), + class_id VARCHAR(255) NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + );`); + yield connection_1.default.raw(`CREATE TABLE Student( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + hobby VARCHAR(50) NULL, + class_id VARCHAR(255) NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + );`); + console.log("Tabelas criadas."); + connection_1.default.destroy(); + } + catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}); +createTables(); +//# sourceMappingURL=createTables.js.map \ No newline at end of file diff --git a/build/database/migrations/createTables.js.map b/build/database/migrations/createTables.js.map new file mode 100644 index 0000000..41062a6 --- /dev/null +++ b/build/database/migrations/createTables.js.map @@ -0,0 +1 @@ +{"version":3,"file":"createTables.js","sourceRoot":"","sources":["../../../src/database/migrations/createTables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuC;AAEvC,MAAM,YAAY,GAAG,GAAwB,EAAE;IAC7C,IAAI;QACF,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;SAQhB,CAAC,CAAC;QACP,MAAM,oBAAU,CAAC,GAAG,CAClB;;;;;;;;SAQG,CACJ,CAAC;QACF,MAAM,oBAAU,CAAC,GAAG,CAClB;;;;;;;;SAQG,CACJ,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,oBAAU,CAAC,OAAO,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AAEF,YAAY,EAAE,CAAC"} \ No newline at end of file diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..82c3c33 --- /dev/null +++ b/build/index.js @@ -0,0 +1,15 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.app = void 0; +const express_1 = __importDefault(require("express")); +const cors_1 = __importDefault(require("cors")); +const routes_1 = require("./routes"); +const app = express_1.default(); +exports.app = app; +app.use(express_1.default.json()); +app.use(cors_1.default()); +app.use(routes_1.router); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map new file mode 100644 index 0000000..17a3742 --- /dev/null +++ b/build/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,qCAAkC;AAElC,MAAM,GAAG,GAAY,iBAAO,EAAE,CAAC;AAMtB,kBAAG;AAJZ,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,cAAI,EAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,eAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/models/insertClass.js b/build/models/insertClass.js new file mode 100644 index 0000000..5a3b2aa --- /dev/null +++ b/build/models/insertClass.js @@ -0,0 +1,20 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertClass = void 0; +const insertClass = () => __awaiter(void 0, void 0, void 0, function* () { + try { + } + catch (error) { + } +}); +exports.insertClass = insertClass; +//# sourceMappingURL=insertClass.js.map \ No newline at end of file diff --git a/build/models/insertClass.js.map b/build/models/insertClass.js.map new file mode 100644 index 0000000..15161d1 --- /dev/null +++ b/build/models/insertClass.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertClass.js","sourceRoot":"","sources":["../../src/models/insertClass.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,WAAW,GAAG,GAAsB,EAAE;IAC/C,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,WAAW,eAMvB"} \ No newline at end of file diff --git a/build/models/insertStudent.js b/build/models/insertStudent.js new file mode 100644 index 0000000..002618d --- /dev/null +++ b/build/models/insertStudent.js @@ -0,0 +1,31 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertStudent = void 0; +const connection_1 = require("./../database/connection"); +const insertStudent = (name, email, birthdate, hobby) => __awaiter(void 0, void 0, void 0, function* () { + try { + yield connection_1.connection + .insert({ + id: Date.now(), + name: name, + email: email, + birthdate: birthdate, + hobby: hobby, + }) + .into("Student"); + } + catch (error) { + console.log(error); + } +}); +exports.insertStudent = insertStudent; +//# sourceMappingURL=insertStudent.js.map \ No newline at end of file diff --git a/build/models/insertStudent.js.map b/build/models/insertStudent.js.map new file mode 100644 index 0000000..14cb9cd --- /dev/null +++ b/build/models/insertStudent.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertStudent.js","sourceRoot":"","sources":["../../src/models/insertStudent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAsD;AAC/C,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,KAAa,EACb,SAAiB,EACjB,KAAa,EACE,EAAE;IACjB,IAAI;QACF,MAAM,uBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,SAAS;YACpB,KAAK,EAAE,KAAK;SACb,CAAC;aACD,IAAI,CAAC,SAAS,CAAC,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC,CAAA,CAAC;AAnBW,QAAA,aAAa,iBAmBxB"} \ No newline at end of file diff --git a/build/models/insertTeacher.js b/build/models/insertTeacher.js new file mode 100644 index 0000000..d0a36f0 --- /dev/null +++ b/build/models/insertTeacher.js @@ -0,0 +1,20 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertTeacher = void 0; +const insertTeacher = () => __awaiter(void 0, void 0, void 0, function* () { + try { + } + catch (error) { + } +}); +exports.insertTeacher = insertTeacher; +//# sourceMappingURL=insertTeacher.js.map \ No newline at end of file diff --git a/build/models/insertTeacher.js.map b/build/models/insertTeacher.js.map new file mode 100644 index 0000000..f3cfa09 --- /dev/null +++ b/build/models/insertTeacher.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insertTeacher.js","sourceRoot":"","sources":["../../src/models/insertTeacher.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,aAAa,GAAG,GAAsB,EAAE;IACjD,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,aAAa,iBAMzB"} \ No newline at end of file diff --git a/build/routes.js b/build/routes.js new file mode 100644 index 0000000..2434d28 --- /dev/null +++ b/build/routes.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const ClassController_1 = require("./controllers/ClassController"); +const StudentController_1 = require("./controllers/StudentController"); +const TeacherController_1 = require("./controllers/TeacherController"); +const router = express_1.Router(); +exports.router = router; +const classController = new ClassController_1.ClassController(); +const studentController = new StudentController_1.StudentController(); +const teacherController = new TeacherController_1.TeacherController(); +router.put("/create-class", classController.create); +router.put("/create-student", studentController.create); +router.put("/create-student", teacherController.create); +//# sourceMappingURL=routes.js.map \ No newline at end of file diff --git a/build/routes.js.map b/build/routes.js.map new file mode 100644 index 0000000..e1dae70 --- /dev/null +++ b/build/routes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mEAAgE;AAChE,uEAAoE;AACpE,uEAAoE;AAEpE,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAUf,wBAAM;AARf,MAAM,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAClD,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAElD,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/server.js b/build/server.js new file mode 100644 index 0000000..7ed959d --- /dev/null +++ b/build/server.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const _1 = require("."); +const server = _1.app.listen(3333, () => { + if (server) { + const address = server.address(); + console.log(`Server is running in http://localhost:${address.port}`); + } + else { + console.error(`Failure upon starting server.`); + } +}); +//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/build/server.js.map b/build/server.js.map new file mode 100644 index 0000000..11dca8b --- /dev/null +++ b/build/server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AAGxB,MAAM,MAAM,GAAG,MAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACnC,IAAI,MAAM,EAAE;QACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,yCAAyC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACtE;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAChD;AACH,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/build/utilities/verifiers.js b/build/utilities/verifiers.js new file mode 100644 index 0000000..42242a8 --- /dev/null +++ b/build/utilities/verifiers.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.checkDate = exports.formatDate = void 0; +const formatDate = (date) => { + const [day, month, year] = date.split("/"); + return `${year}-${month}-${day}`; +}; +exports.formatDate = formatDate; +const checkDate = (date) => { + const useBar = date.includes("/"); + if (useBar) { + return true; + } + else { + return false; + } +}; +exports.checkDate = checkDate; +//# sourceMappingURL=verifiers.js.map \ No newline at end of file diff --git a/build/utilities/verifiers.js.map b/build/utilities/verifiers.js.map new file mode 100644 index 0000000..2e22dc1 --- /dev/null +++ b/build/utilities/verifiers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"verifiers.js","sourceRoot":"","sources":["../../src/utilities/verifiers.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAC/C,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC,CAAC;AAHS,QAAA,UAAU,cAGnB;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,MAAM,EAAE;QACV,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB"} \ No newline at end of file diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 0799dc0..94e9f24 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -1,14 +1,35 @@ +import { formatDate } from "./../utilities/verifiers"; +import { insertStudent } from "./../models/insertStudent"; import { Request, Response } from "express"; - +import { checkDate } from "../utilities/verifiers"; class StudentController { - async create(req:Request, res: Response) { - try { + async create(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { name, email, birthdate, hobby } = req.body; + + if (!name || !email || !birthdate || !hobby) { + errorCode = 422; + throw new Error( + "Preencha todas as informações necessarias para adicionar um estudante !" + ); + } - } catch (error) { - - } + const checkingDate = checkDate(birthdate); + if (!checkingDate) { + errorCode = 406; + throw new Error("Coloque uma data formato DD/MM/YYYY"); + } + const formatingDate = formatDate(birthdate); + await insertStudent(name, email, formatingDate, hobby); + res.status(201).send({ + message: `Estudante ${name} adicionado a turma !`, + }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); } + } } -export {StudentController} \ No newline at end of file +export { StudentController }; diff --git a/src/database/migrations/createTables.ts b/src/database/migrations/createTables.ts index fa75616..fd1a75e 100644 --- a/src/database/migrations/createTables.ts +++ b/src/database/migrations/createTables.ts @@ -3,35 +3,36 @@ import connection from "../connection"; const createTables = async (): Promise => { try { await connection.raw(` - CREATE TABLE Class( - id INT PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - start_date DATE NOT NULL, - end_date DATE NOT NULL, - module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", - type ENUM ("full-time class", "-na-night") - `); - await connection.raw(` - CREATE TABLE Teacher( - id INT PRIMARY KEY NOT NULL, + CREATE TABLE Class( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + start_date DATE NOT NULL, + end_date DATE NOT NULL, + module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", + type ENUM ("full-time class", "-na-night") + );`); + await connection.raw( + `CREATE TABLE Teacher( + id VARCHAR(255) PRIMARY KEY NOT NULL, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL UNIQUE, birthdate DATE NOT NULL, speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), - class_id INT NOT NULL, - FOREIGN KEY (class_id) REFERENCES Class(id) - ); - `); - await connection.raw(` - CREATE TABLE Student( - id INT PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL UNIQUE, - birthdate DATE NOT NULL, - hobby VARCHAR(50) NULL, - class_id INT NOT NULL, + class_id VARCHAR(255) NULL, FOREIGN KEY (class_id) REFERENCES Class(id) - `); + );` + ); + await connection.raw( + `CREATE TABLE Student( + id VARCHAR(255) PRIMARY KEY NOT NULL, + name VARCHAR(50) NOT NULL, + email VARCHAR(50) NOT NULL UNIQUE, + birthdate DATE NOT NULL, + hobby VARCHAR(50) NULL, + class_id VARCHAR(255) NULL, + FOREIGN KEY (class_id) REFERENCES Class(id) + );` + ); console.log("Tabelas criadas."); connection.destroy(); } catch (error) { diff --git a/src/models/insertStudent.ts b/src/models/insertStudent.ts index 1fa8665..5a58b7c 100644 --- a/src/models/insertStudent.ts +++ b/src/models/insertStudent.ts @@ -1,7 +1,21 @@ -export const insertStudent = async():Promise => { - try { - - } catch (error) { - - } -} \ No newline at end of file +import { connection } from "./../database/connection"; +export const insertStudent = async ( + name: string, + email: string, + birthdate: string, + hobby: string +): Promise => { + try { + await connection + .insert({ + id: Date.now(), + name: name, + email: email, + birthdate: birthdate, + hobby: hobby, + }) + .into("Student"); + } catch (error) { + console.log(error); + } +}; diff --git a/src/utilities/verifiers.ts b/src/utilities/verifiers.ts index 0be134c..0c528a2 100644 --- a/src/utilities/verifiers.ts +++ b/src/utilities/verifiers.ts @@ -1 +1,15 @@ -teste. \ No newline at end of file +export const formatDate = (date: string): string => { + const [day, month, year] = date.split("/"); + return `${year}-${month}-${day}`; + }; + + export const checkDate = (date: string): boolean => { + const useBar = date.includes("/"); + + if (useBar) { + return true; + } else { + return false; + } + }; + \ No newline at end of file From b6f51be6464093d16dd4f393023e18e10d2de768 Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Tue, 30 Mar 2021 17:17:55 -0300 Subject: [PATCH 09/30] teste --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 66227fd..525c635 100644 --- a/.gitignore +++ b/.gitignore @@ -123,4 +123,5 @@ dist/ # Temporary folders tmp/ -temp/ \ No newline at end of file +temp/ +build/ \ No newline at end of file From 1818718600d44e8ac415692b3f97b0fb895b6253 Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Tue, 30 Mar 2021 17:18:26 -0300 Subject: [PATCH 10/30] =?UTF-8?q?Cria=C3=A7=C3=A3o=20Students?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/controllers/ClassController.js | 23 -------- build/controllers/ClassController.js.map | 1 - build/controllers/StudentController.js | 36 ------------- build/controllers/StudentController.js.map | 1 - build/controllers/TeacherController.js | 24 --------- build/controllers/TeacherController.js.map | 1 - build/database/connection.js | 22 -------- build/database/connection.js.map | 1 - build/database/migrations/createTables.js | 53 ------------------- build/database/migrations/createTables.js.map | 1 - build/index.js | 15 ------ build/index.js.map | 1 - build/models/insertClass.js | 20 ------- build/models/insertClass.js.map | 1 - build/models/insertStudent.js | 31 ----------- build/models/insertStudent.js.map | 1 - build/models/insertTeacher.js | 20 ------- build/models/insertTeacher.js.map | 1 - build/routes.js | 16 ------ build/routes.js.map | 1 - build/server.js | 13 ----- build/server.js.map | 1 - build/utilities/verifiers.js | 19 ------- build/utilities/verifiers.js.map | 1 - 24 files changed, 304 deletions(-) delete mode 100644 build/controllers/ClassController.js delete mode 100644 build/controllers/ClassController.js.map delete mode 100644 build/controllers/StudentController.js delete mode 100644 build/controllers/StudentController.js.map delete mode 100644 build/controllers/TeacherController.js delete mode 100644 build/controllers/TeacherController.js.map delete mode 100644 build/database/connection.js delete mode 100644 build/database/connection.js.map delete mode 100644 build/database/migrations/createTables.js delete mode 100644 build/database/migrations/createTables.js.map delete mode 100644 build/index.js delete mode 100644 build/index.js.map delete mode 100644 build/models/insertClass.js delete mode 100644 build/models/insertClass.js.map delete mode 100644 build/models/insertStudent.js delete mode 100644 build/models/insertStudent.js.map delete mode 100644 build/models/insertTeacher.js delete mode 100644 build/models/insertTeacher.js.map delete mode 100644 build/routes.js delete mode 100644 build/routes.js.map delete mode 100644 build/server.js delete mode 100644 build/server.js.map delete mode 100644 build/utilities/verifiers.js delete mode 100644 build/utilities/verifiers.js.map diff --git a/build/controllers/ClassController.js b/build/controllers/ClassController.js deleted file mode 100644 index c0f8547..0000000 --- a/build/controllers/ClassController.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ClassController = void 0; -class ClassController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - try { - } - catch (error) { } - }); - } -} -exports.ClassController = ClassController; -//# sourceMappingURL=ClassController.js.map \ No newline at end of file diff --git a/build/controllers/ClassController.js.map b/build/controllers/ClassController.js.map deleted file mode 100644 index 673cf02..0000000 --- a/build/controllers/ClassController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ClassController.js","sourceRoot":"","sources":["../../src/controllers/ClassController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,MAAM,eAAe;IACb,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI;aACH;YAAC,OAAO,KAAK,EAAE,GAAE;QACpB,CAAC;KAAA;CACF;AAEQ,0CAAe"} \ No newline at end of file diff --git a/build/controllers/StudentController.js b/build/controllers/StudentController.js deleted file mode 100644 index 1d9ee06..0000000 --- a/build/controllers/StudentController.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.StudentController = void 0; -const insertStudent_1 = require("./../models/insertStudent"); -class StudentController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - let errorCode = 400; - try { - const { name, email, birthdate, hobby } = req.body; - if (!name || !email || !birthdate || !hobby) { - errorCode = 422; - throw new Error("Preencha todas as informações necessarias para adicionar um estudante !"); - } - yield insertStudent_1.insertStudent(name, email, birthdate, hobby); - res.status(201).send({ - message: `Estudante ${name} adicionado a turma !`, - }); - } - catch (error) { - res.status(errorCode).send({ message: error.message }); - } - }); - } -} -exports.StudentController = StudentController; -//# sourceMappingURL=StudentController.js.map \ No newline at end of file diff --git a/build/controllers/StudentController.js.map b/build/controllers/StudentController.js.map deleted file mode 100644 index d0c237d..0000000 --- a/build/controllers/StudentController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"StudentController.js","sourceRoot":"","sources":["../../src/controllers/StudentController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAA0D;AAG1D,MAAM,iBAAiB;IACf,MAAM,CAAC,GAAY,EAAE,GAAa;;YACtC,IAAI,SAAS,GAAW,GAAG,CAAC;YAC5B,IAAI;gBACF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;gBACnD,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;oBAC3C,SAAS,GAAG,GAAG,CAAC;oBAChB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;iBACH;gBACD,MAAM,6BAAa,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,aAAa,IAAI,uBAAuB;iBAClD,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aACxD;QACH,CAAC;KAAA;CACF;AAEQ,8CAAiB"} \ No newline at end of file diff --git a/build/controllers/TeacherController.js b/build/controllers/TeacherController.js deleted file mode 100644 index 20b79b1..0000000 --- a/build/controllers/TeacherController.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TeacherController = void 0; -class TeacherController { - create(req, res) { - return __awaiter(this, void 0, void 0, function* () { - try { - } - catch (error) { - } - }); - } -} -exports.TeacherController = TeacherController; -//# sourceMappingURL=TeacherController.js.map \ No newline at end of file diff --git a/build/controllers/TeacherController.js.map b/build/controllers/TeacherController.js.map deleted file mode 100644 index 8188e02..0000000 --- a/build/controllers/TeacherController.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"TeacherController.js","sourceRoot":"","sources":["../../src/controllers/TeacherController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,MAAM,iBAAiB;IACb,MAAM,CAAC,GAAW,EAAE,GAAa;;YACnC,IAAI;aAEH;YAAC,OAAO,KAAK,EAAE;aAEf;QACL,CAAC;KAAA;CACJ;AAEO,8CAAiB"} \ No newline at end of file diff --git a/build/database/connection.js b/build/database/connection.js deleted file mode 100644 index 2feb930..0000000 --- a/build/database/connection.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.connection = void 0; -const knex_1 = __importDefault(require("knex")); -const dotenv_1 = __importDefault(require("dotenv")); -dotenv_1.default.config(); -exports.connection = knex_1.default({ - client: "mysql", - connection: { - host: process.env.DB_HOST, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_SCHEMA, - port: 3306, - multipleStatements: true, - }, -}); -exports.default = exports.connection; -//# sourceMappingURL=connection.js.map \ No newline at end of file diff --git a/build/database/connection.js.map b/build/database/connection.js.map deleted file mode 100644 index e94c618..0000000 --- a/build/database/connection.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/database/connection.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEH,QAAA,UAAU,GAAG,cAAI,CAAC;IAC7B,MAAM,EAAE,OAAO;IACf,UAAU,EAAE;QACV,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC/B,IAAI,EAAE,IAAI;QACV,kBAAkB,EAAE,IAAI;KACzB;CACF,CAAC,CAAC;AAEH,kBAAe,kBAAU,CAAC"} \ No newline at end of file diff --git a/build/database/migrations/createTables.js b/build/database/migrations/createTables.js deleted file mode 100644 index 08ad60a..0000000 --- a/build/database/migrations/createTables.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const connection_1 = __importDefault(require("../connection")); -const createTables = () => __awaiter(void 0, void 0, void 0, function* () { - try { - yield connection_1.default.raw(` - CREATE TABLE Class( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - start_date DATE NOT NULL, - end_date DATE NOT NULL, - module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", - type ENUM ("full-time class", "-na-night") - );`); - yield connection_1.default.raw(`CREATE TABLE Teacher( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL UNIQUE, - birthdate DATE NOT NULL, - speciality ENUM ("React", "Redux", "CSS", "Testes", "Typescript", "Programação Orientada a Objetos", "Backend"), - class_id VARCHAR(255) NULL, - FOREIGN KEY (class_id) REFERENCES Class(id) - );`); - yield connection_1.default.raw(`CREATE TABLE Student( - id VARCHAR(255) PRIMARY KEY NOT NULL, - name VARCHAR(50) NOT NULL, - email VARCHAR(50) NOT NULL UNIQUE, - birthdate DATE NOT NULL, - hobby VARCHAR(50) NULL, - class_id VARCHAR(255) NULL, - FOREIGN KEY (class_id) REFERENCES Class(id) - );`); - console.log("Tabelas criadas."); - connection_1.default.destroy(); - } - catch (error) { - throw new Error(error.message || error.sqlMessage); - } -}); -createTables(); -//# sourceMappingURL=createTables.js.map \ No newline at end of file diff --git a/build/database/migrations/createTables.js.map b/build/database/migrations/createTables.js.map deleted file mode 100644 index 41062a6..0000000 --- a/build/database/migrations/createTables.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createTables.js","sourceRoot":"","sources":["../../../src/database/migrations/createTables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuC;AAEvC,MAAM,YAAY,GAAG,GAAwB,EAAE;IAC7C,IAAI;QACF,MAAM,oBAAU,CAAC,GAAG,CAAC;;;;;;;;SAQhB,CAAC,CAAC;QACP,MAAM,oBAAU,CAAC,GAAG,CAClB;;;;;;;;SAQG,CACJ,CAAC;QACF,MAAM,oBAAU,CAAC,GAAG,CAClB;;;;;;;;SAQG,CACJ,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChC,oBAAU,CAAC,OAAO,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC;AAEF,YAAY,EAAE,CAAC"} \ No newline at end of file diff --git a/build/index.js b/build/index.js deleted file mode 100644 index 82c3c33..0000000 --- a/build/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.app = void 0; -const express_1 = __importDefault(require("express")); -const cors_1 = __importDefault(require("cors")); -const routes_1 = require("./routes"); -const app = express_1.default(); -exports.app = app; -app.use(express_1.default.json()); -app.use(cors_1.default()); -app.use(routes_1.router); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map deleted file mode 100644 index 17a3742..0000000 --- a/build/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA2C;AAC3C,gDAAwB;AACxB,qCAAkC;AAElC,MAAM,GAAG,GAAY,iBAAO,EAAE,CAAC;AAMtB,kBAAG;AAJZ,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,cAAI,EAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,eAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/models/insertClass.js b/build/models/insertClass.js deleted file mode 100644 index 5a3b2aa..0000000 --- a/build/models/insertClass.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertClass = void 0; -const insertClass = () => __awaiter(void 0, void 0, void 0, function* () { - try { - } - catch (error) { - } -}); -exports.insertClass = insertClass; -//# sourceMappingURL=insertClass.js.map \ No newline at end of file diff --git a/build/models/insertClass.js.map b/build/models/insertClass.js.map deleted file mode 100644 index 15161d1..0000000 --- a/build/models/insertClass.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertClass.js","sourceRoot":"","sources":["../../src/models/insertClass.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,WAAW,GAAG,GAAsB,EAAE;IAC/C,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,WAAW,eAMvB"} \ No newline at end of file diff --git a/build/models/insertStudent.js b/build/models/insertStudent.js deleted file mode 100644 index 002618d..0000000 --- a/build/models/insertStudent.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertStudent = void 0; -const connection_1 = require("./../database/connection"); -const insertStudent = (name, email, birthdate, hobby) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield connection_1.connection - .insert({ - id: Date.now(), - name: name, - email: email, - birthdate: birthdate, - hobby: hobby, - }) - .into("Student"); - } - catch (error) { - console.log(error); - } -}); -exports.insertStudent = insertStudent; -//# sourceMappingURL=insertStudent.js.map \ No newline at end of file diff --git a/build/models/insertStudent.js.map b/build/models/insertStudent.js.map deleted file mode 100644 index 14cb9cd..0000000 --- a/build/models/insertStudent.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertStudent.js","sourceRoot":"","sources":["../../src/models/insertStudent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAsD;AAC/C,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,KAAa,EACb,SAAiB,EACjB,KAAa,EACE,EAAE;IACjB,IAAI;QACF,MAAM,uBAAU;aACb,MAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,SAAS;YACpB,KAAK,EAAE,KAAK;SACb,CAAC;aACD,IAAI,CAAC,SAAS,CAAC,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC,CAAA,CAAC;AAnBW,QAAA,aAAa,iBAmBxB"} \ No newline at end of file diff --git a/build/models/insertTeacher.js b/build/models/insertTeacher.js deleted file mode 100644 index d0a36f0..0000000 --- a/build/models/insertTeacher.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.insertTeacher = void 0; -const insertTeacher = () => __awaiter(void 0, void 0, void 0, function* () { - try { - } - catch (error) { - } -}); -exports.insertTeacher = insertTeacher; -//# sourceMappingURL=insertTeacher.js.map \ No newline at end of file diff --git a/build/models/insertTeacher.js.map b/build/models/insertTeacher.js.map deleted file mode 100644 index f3cfa09..0000000 --- a/build/models/insertTeacher.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"insertTeacher.js","sourceRoot":"","sources":["../../src/models/insertTeacher.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,aAAa,GAAG,GAAsB,EAAE;IACjD,IAAI;KAEH;IAAC,OAAO,KAAK,EAAE;KAEf;AACL,CAAC,CAAA,CAAA;AANY,QAAA,aAAa,iBAMzB"} \ No newline at end of file diff --git a/build/routes.js b/build/routes.js deleted file mode 100644 index 2434d28..0000000 --- a/build/routes.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.router = void 0; -const express_1 = require("express"); -const ClassController_1 = require("./controllers/ClassController"); -const StudentController_1 = require("./controllers/StudentController"); -const TeacherController_1 = require("./controllers/TeacherController"); -const router = express_1.Router(); -exports.router = router; -const classController = new ClassController_1.ClassController(); -const studentController = new StudentController_1.StudentController(); -const teacherController = new TeacherController_1.TeacherController(); -router.put("/create-class", classController.create); -router.put("/create-student", studentController.create); -router.put("/create-student", teacherController.create); -//# sourceMappingURL=routes.js.map \ No newline at end of file diff --git a/build/routes.js.map b/build/routes.js.map deleted file mode 100644 index e1dae70..0000000 --- a/build/routes.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mEAAgE;AAChE,uEAAoE;AACpE,uEAAoE;AAEpE,MAAM,MAAM,GAAG,gBAAM,EAAE,CAAC;AAUf,wBAAM;AARf,MAAM,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAClD,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,EAAE,CAAC;AAElD,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;AACpD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/build/server.js b/build/server.js deleted file mode 100644 index 7ed959d..0000000 --- a/build/server.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const _1 = require("."); -const server = _1.app.listen(3333, () => { - if (server) { - const address = server.address(); - console.log(`Server is running in http://localhost:${address.port}`); - } - else { - console.error(`Failure upon starting server.`); - } -}); -//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/build/server.js.map b/build/server.js.map deleted file mode 100644 index 11dca8b..0000000 --- a/build/server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAAA,wBAAwB;AAGxB,MAAM,MAAM,GAAG,MAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACnC,IAAI,MAAM,EAAE;QACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,yCAAyC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACtE;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAChD;AACH,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/build/utilities/verifiers.js b/build/utilities/verifiers.js deleted file mode 100644 index 42242a8..0000000 --- a/build/utilities/verifiers.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkDate = exports.formatDate = void 0; -const formatDate = (date) => { - const [day, month, year] = date.split("/"); - return `${year}-${month}-${day}`; -}; -exports.formatDate = formatDate; -const checkDate = (date) => { - const useBar = date.includes("/"); - if (useBar) { - return true; - } - else { - return false; - } -}; -exports.checkDate = checkDate; -//# sourceMappingURL=verifiers.js.map \ No newline at end of file diff --git a/build/utilities/verifiers.js.map b/build/utilities/verifiers.js.map deleted file mode 100644 index 2e22dc1..0000000 --- a/build/utilities/verifiers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"verifiers.js","sourceRoot":"","sources":["../../src/utilities/verifiers.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAC/C,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC,CAAC;AAHS,QAAA,UAAU,cAGnB;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,MAAM,EAAE;QACV,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB"} \ No newline at end of file From d77ec08b9ee09579534d76eb15bc3316dbf298e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 17:43:07 -0300 Subject: [PATCH 11/30] =?UTF-8?q?Cria=C3=A7=C3=A3o=20de=20turmas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ClassController.ts | 25 ++++++++++++++++++++++++- src/models/insertClass.ts | 18 +++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts index 6aa679d..7b707de 100644 --- a/src/controllers/ClassController.ts +++ b/src/controllers/ClassController.ts @@ -1,12 +1,35 @@ import { Request, Response } from "express"; import { insertClass } from "../models/insertClass"; +import { checkDate, formatDate } from "../utilities/verifiers"; class ClassController { async create(req: Request, res: Response) { let errorCode: number = 404; try { const { name, start_date, end_date, module, type } = req.body; - (await insertClass(name, start_date, end_date, module, type)) as string; + const checkingStartDate = checkDate(start_date); + const checkingEndDate = checkDate(end_date); + if (!name || !module || !type) { + errorCode = 422; + throw new Error("Preencha corretamente os campos para a criação!"); + } + if (!checkingStartDate) { + errorCode = 406; + throw new Error("Coloque a data de inicio no formato DD/MM/YYYY"); + } + if (!checkingEndDate) { + errorCode = 406; + throw new Error("Coloque a data final no formato DD/MM/YYYY"); + } + const convertStartDate = formatDate(start_date); + const convertEndDate = formatDate(end_date); + (await insertClass( + name, + convertStartDate, + convertEndDate, + module, + type + )) as string; res.status(201).send({ message: "Turma criada com sucesso." }); } catch (error) { res.status(errorCode).send({ message: error.message }); diff --git a/src/models/insertClass.ts b/src/models/insertClass.ts index 05c4495..c4f581c 100644 --- a/src/models/insertClass.ts +++ b/src/models/insertClass.ts @@ -1,7 +1,23 @@ import connection from "../database/connection"; -export const insertClass = async (): Promise => { +export const insertClass = async ( + name: string, + start_date: string, + end_date: string, + module: string, + type: string +): Promise => { try { + await connection + .insert({ + id: Date.now(), + name, + start_date, + end_date, + module, + type, + }) + .into("Class"); } catch (error) { throw new Error(error.message || error.sqlMessage); } From 68676df9a7a89e2b38daa48fb450cf5f7f54a040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 18:30:12 -0300 Subject: [PATCH 12/30] Adicionando docentes a turmas --- src/controllers/TeacherController.ts | 18 ++++++++++++++++++ src/models/insertTeacherInClass.ts | 14 ++++++++++++++ src/routes.ts | 1 + 3 files changed, 33 insertions(+) create mode 100644 src/models/insertTeacherInClass.ts diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index 12b715d..8554875 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -1,5 +1,6 @@ import { Request, Response } from "express"; import { insertTeacher } from "../models/insertTeacher"; +import { insertTeacherInClass } from "../models/insertTeacherInClass"; import { checkDate, formatDate } from "../utilities/verifiers"; class TeacherController { @@ -25,6 +26,23 @@ class TeacherController { res.status(errorCode).send({ message: error.message }); } } + + async execute(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { class_id, teacher_id } = req.body; + if (!class_id || !teacher_id) { + errorCode = 422; + throw new Error( + "Preencha os campos do ID da class e do ID do docente para prosseguir." + ); + } + (await insertTeacherInClass(class_id, teacher_id)) as string; + res.status(200).send({ message: "O professor foi inserido na turma" }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } } export { TeacherController }; diff --git a/src/models/insertTeacherInClass.ts b/src/models/insertTeacherInClass.ts new file mode 100644 index 0000000..9907a72 --- /dev/null +++ b/src/models/insertTeacherInClass.ts @@ -0,0 +1,14 @@ +import connection from "../database/connection"; + +export const insertTeacherInClass = async ( + class_id: string, + id: string +): Promise => { + try { + await connection.raw(` + UPDATE Teacher SET class_id = ${class_id} WHERE id = ${id} + `); + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 37bedef..bb6d655 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -12,5 +12,6 @@ const teacherController = new TeacherController(); router.put("/create-class", classController.create); router.put("/create-student", studentController.create); router.put("/create-teacher", teacherController.create); +router.post("/teacher-class", teacherController.execute); export { router }; From 7f614d70a3ce0ba164518d131be7b93375119b4f Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Tue, 30 Mar 2021 18:30:34 -0300 Subject: [PATCH 13/30] idade do estudante --- src/controllers/StudentAgeController.ts | 23 +++++++++++++++++++++++ src/models/selectStudentAgeById.ts | 15 +++++++++++++++ src/routes.ts | 3 +++ 3 files changed, 41 insertions(+) create mode 100644 src/controllers/StudentAgeController.ts create mode 100644 src/models/selectStudentAgeById.ts diff --git a/src/controllers/StudentAgeController.ts b/src/controllers/StudentAgeController.ts new file mode 100644 index 0000000..5d1f44c --- /dev/null +++ b/src/controllers/StudentAgeController.ts @@ -0,0 +1,23 @@ +import { selectStudentAgeById } from "./../models/selectStudentAgeById"; +import { Request, Response } from "express"; + +class StudentAgeController { + async show(req: Request, res: Response) { + try { + const id = req.params.id; + + if (!id) { + throw new Error("id não existe"); + } + + const result = await selectStudentAgeById(id); + + res.status(200).send({ message: "Idade do estudante é", result }); + } catch (error) { + console.log(error); + res.status(422).send(error.sqlMessage || error.message); + } + } +} + +export { StudentAgeController }; diff --git a/src/models/selectStudentAgeById.ts b/src/models/selectStudentAgeById.ts new file mode 100644 index 0000000..ab86a6c --- /dev/null +++ b/src/models/selectStudentAgeById.ts @@ -0,0 +1,15 @@ +import connection from "../database/connection"; + +export const selectStudentAgeById = async (id: string): Promise => { + try { + const result = await connection.raw(` + SELECT DATEDIFF(CURDATE(),birthdate)/365 + FROM Student + WHERE id=${id} + `); + + return result[0]; + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 37bedef..1e21f14 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -2,15 +2,18 @@ import { Router } from "express"; import { ClassController } from "./controllers/ClassController"; import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; +import {StudentAgeController} from "./controllers/StudentAgeController" const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); +const studentAgeController = new StudentAgeController(); router.put("/create-class", classController.create); router.put("/create-student", studentController.create); router.put("/create-teacher", teacherController.create); +router.get("/student/:id", studentAgeController.show ) export { router }; From 5f29aad2538eb35d99422271f885119196d58fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 18:53:56 -0300 Subject: [PATCH 14/30] =?UTF-8?q?Ajustes=20da=20valida=C3=A7=C3=A3o=20para?= =?UTF-8?q?=20selecionar=20o=20estudante?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StudentController.ts | 19 ++++++++++++++++++- src/models/selectStudentAgeById.ts | 4 ++-- src/routes.ts | 4 +--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 94e9f24..89ed27c 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -2,6 +2,7 @@ import { formatDate } from "./../utilities/verifiers"; import { insertStudent } from "./../models/insertStudent"; import { Request, Response } from "express"; import { checkDate } from "../utilities/verifiers"; +import { selectStudentAgeById } from "../models/selectStudentAgeById"; class StudentController { async create(req: Request, res: Response) { @@ -24,12 +25,28 @@ class StudentController { const formatingDate = formatDate(birthdate); await insertStudent(name, email, formatingDate, hobby); res.status(201).send({ - message: `Estudante ${name} adicionado a turma !`, + message: `Estudante ${name} adicionado a turma!`, }); } catch (error) { res.status(errorCode).send({ message: error.message }); } } + + async show(req: Request, res: Response) { + let errorCode: number = 400; + try { + const id = req.params.id; + if (!id) { + errorCode = 422; + throw new Error("Id não existe!"); + } + const result = (await selectStudentAgeById(id)) as string; + res.status(200).send({ message: result }); + } catch (error) { + console.log(error); + res.status(errorCode).send({ message: error.message }); + } + } } export { StudentController }; diff --git a/src/models/selectStudentAgeById.ts b/src/models/selectStudentAgeById.ts index ab86a6c..c93ea9e 100644 --- a/src/models/selectStudentAgeById.ts +++ b/src/models/selectStudentAgeById.ts @@ -3,12 +3,12 @@ import connection from "../database/connection"; export const selectStudentAgeById = async (id: string): Promise => { try { const result = await connection.raw(` - SELECT DATEDIFF(CURDATE(),birthdate)/365 + SELECT name, FLOOR( DATEDIFF(CURDATE(),birthdate)/365) as Age FROM Student WHERE id=${id} `); - return result[0]; + return result[0][0]; } catch (error) { throw new Error(error.message || error.sqlMessage); } diff --git a/src/routes.ts b/src/routes.ts index 1e21f14..ac35136 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -2,18 +2,16 @@ import { Router } from "express"; import { ClassController } from "./controllers/ClassController"; import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; -import {StudentAgeController} from "./controllers/StudentAgeController" const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); -const studentAgeController = new StudentAgeController(); router.put("/create-class", classController.create); router.put("/create-student", studentController.create); router.put("/create-teacher", teacherController.create); -router.get("/student/:id", studentAgeController.show ) +router.get("/student/:id", studentController.show); export { router }; From d79e8a89b7a0ab06b267046e0ad032cf74f55f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Victor=20T=2E=20Ferreira?= <74377057+josevictorsss@users.noreply.github.com> Date: Tue, 30 Mar 2021 19:07:31 -0300 Subject: [PATCH 15/30] Update README.md --- README.md | 73 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 9e4a7d0..12ef622 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,39 @@ -## 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 + +## 💻 Documentação +Teste as rotas com a documentação, basta importar ela para seu postman. + +[Postman - LabenuSystem]() + +## ✨ Tecnologias +Esse projeto foi desenvolvido com as seguintes tecnologias: + +* Node +* Express +* Typescript +* Cors +* Knex +* MySQL +* Dotenv + +## 🚀 Como executar +* Clone o repositório +``` + $https://github.com/future4code/epps-labenu-system6.git + ``` +* Instale as dependências com +``` +npm install + ``` +* Crie as tabelas com + ``` +npm run table + ``` +* Inicie o servidor com + ``` +npm run dev + ``` + + ## Desenvolvido por: + - [José Victor](https://www.linkedin.com/in/jose-victor-tf/) + - [Daniel Ratti](https://www.linkedin.com/in/daniel-ratti-b81721208/) From c777a6102ed8b0b68c1339083053122603bab89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Tue, 30 Mar 2021 19:12:40 -0300 Subject: [PATCH 16/30] Deletando arquivo inutilizado --- src/controllers/StudentAgeController.ts | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/controllers/StudentAgeController.ts diff --git a/src/controllers/StudentAgeController.ts b/src/controllers/StudentAgeController.ts deleted file mode 100644 index 5d1f44c..0000000 --- a/src/controllers/StudentAgeController.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { selectStudentAgeById } from "./../models/selectStudentAgeById"; -import { Request, Response } from "express"; - -class StudentAgeController { - async show(req: Request, res: Response) { - try { - const id = req.params.id; - - if (!id) { - throw new Error("id não existe"); - } - - const result = await selectStudentAgeById(id); - - res.status(200).send({ message: "Idade do estudante é", result }); - } catch (error) { - console.log(error); - res.status(422).send(error.sqlMessage || error.message); - } - } -} - -export { StudentAgeController }; From 09e235e8630cfe4a463646a8d0af8f06b83bc56f Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Tue, 30 Mar 2021 20:46:29 -0300 Subject: [PATCH 17/30] adicionando aluno a turma --- src/controllers/StudentController.ts | 16 ++++++++++++++++ src/models/insertStudentInClass.ts | 17 +++++++++++++++++ src/routes.ts | 1 + 3 files changed, 34 insertions(+) create mode 100644 src/models/insertStudentInClass.ts diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 89ed27c..fbb3eb3 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -3,6 +3,7 @@ import { insertStudent } from "./../models/insertStudent"; import { Request, Response } from "express"; import { checkDate } from "../utilities/verifiers"; import { selectStudentAgeById } from "../models/selectStudentAgeById"; +import { insertStudentInClass } from "../models/insertStudentInClass"; class StudentController { async create(req: Request, res: Response) { @@ -32,6 +33,21 @@ class StudentController { } } + async execute(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { class_id, student_id } = req.body; + if (!class_id || !student_id) { + errorCode = 422; + throw new Error("Preencha os campos do ID da class e do ID do aluno!"); + } + await insertStudentInClass(class_id, student_id); + res.status(200).send({ message: "O aluno foi inserido na turma" }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } + async show(req: Request, res: Response) { let errorCode: number = 400; try { diff --git a/src/models/insertStudentInClass.ts b/src/models/insertStudentInClass.ts new file mode 100644 index 0000000..e81f368 --- /dev/null +++ b/src/models/insertStudentInClass.ts @@ -0,0 +1,17 @@ +import connection from "../database/connection"; + +export const insertStudentInClass = async ( + class_id: string, + id:string +): Promise => { + try { + await connection.raw(` + UPDATE Student SET class_id = ${class_id} WHERE id = ${id} + `).then((res)=>{console.log(res); + }); + } catch (error) { + console.log(error); + + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 5445b30..74d303a 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -14,5 +14,6 @@ router.put("/create-student", studentController.create); router.put("/create-teacher", teacherController.create); router.get("/student/:id", studentController.show); router.post("/teacher-class", teacherController.execute); +router.post("/student-class", studentController.execute); export { router }; From 33f115db32a10dc91fcfd4075e1e1b7539510ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 12:16:54 -0300 Subject: [PATCH 18/30] Exibindo docentes de uma turma --- src/controllers/TeacherController.ts | 20 ++++++++++++++++++++ src/models/selectTeachersFromClass.ts | 17 +++++++++++++++++ src/routes.ts | 7 +++++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/models/selectTeachersFromClass.ts diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index 8554875..9a83ca9 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -1,6 +1,7 @@ import { Request, Response } from "express"; import { insertTeacher } from "../models/insertTeacher"; import { insertTeacherInClass } from "../models/insertTeacherInClass"; +import { selectTeachersFromClass } from "../models/selectTeachersFromClass"; import { checkDate, formatDate } from "../utilities/verifiers"; class TeacherController { @@ -43,6 +44,25 @@ class TeacherController { res.status(errorCode).send({ message: error.message }); } } + + async show(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { id } = req.params; + if (!id) { + errorCode = 404; + throw new Error("Insira um ID válido."); + } + const result = await selectTeachersFromClass(id); + if (!result.length) { + errorCode = 404; + throw new Error("Nenhum docente está na turma!"); + } + res.status(200).send({ message: result }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } } export { TeacherController }; diff --git a/src/models/selectTeachersFromClass.ts b/src/models/selectTeachersFromClass.ts new file mode 100644 index 0000000..5ef8f82 --- /dev/null +++ b/src/models/selectTeachersFromClass.ts @@ -0,0 +1,17 @@ +import connection from "../database/connection"; + +export const selectTeachersFromClass = async (id: string): Promise => { + try { + const result = await connection.raw(` + SELECT Teacher.name + as Teacher,Teacher.speciality + as Speciality, Class.name + as Class FROM Teacher + LEFT JOIN Class on Teacher.class_id = Class.id + WHERE Teacher.class_id = "${id}" + `); + return result[0]; + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 5445b30..7c30043 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -10,9 +10,12 @@ const studentController = new StudentController(); const teacherController = new TeacherController(); router.put("/create-class", classController.create); + router.put("/create-student", studentController.create); -router.put("/create-teacher", teacherController.create); router.get("/student/:id", studentController.show); -router.post("/teacher-class", teacherController.execute); + +router.put("/teacher/create", teacherController.create); +router.post("/teacher/class", teacherController.execute); +router.get("/teacher/class/:id", teacherController.show); export { router }; From 9ab5831752d309505245632c1b464f2a049d55c4 Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Wed, 31 Mar 2021 12:26:49 -0300 Subject: [PATCH 19/30] filtrar estudantes por classe --- src/controllers/GetClassInfoController.ts | 25 +++++++++++++++++++++++ src/models/selectStudentByClass.ts | 15 ++++++++++++++ src/routes.ts | 7 +++++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/controllers/GetClassInfoController.ts create mode 100644 src/models/selectStudentByClass.ts diff --git a/src/controllers/GetClassInfoController.ts b/src/controllers/GetClassInfoController.ts new file mode 100644 index 0000000..fa3f9cb --- /dev/null +++ b/src/controllers/GetClassInfoController.ts @@ -0,0 +1,25 @@ +import { Request, Response } from "express"; +import { selectStudentByClass } from "../models/selectStudentByClass"; + +class GetClassInfoController { + async show(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { id } = req.params; + if (!id) { + errorCode = 404; + throw new Error("Insira um ID válido."); + } + const result = await selectStudentByClass(id); + if (!result.length) { + errorCode = 404; + throw new Error("Nenhum docente está na turma!"); + } + res.status(200).send({ message: result }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } +} + +export { GetClassInfoController }; diff --git a/src/models/selectStudentByClass.ts b/src/models/selectStudentByClass.ts new file mode 100644 index 0000000..4715fb5 --- /dev/null +++ b/src/models/selectStudentByClass.ts @@ -0,0 +1,15 @@ +import connection from "../database/connection"; + +export const selectStudentByClass = async (id: string): Promise => { + try { + const result = await connection.raw(` + SELECT Student.name as Student,Student.hobby as Hobby, Class.name + as Class FROM Student LEFT JOIN Class on Student.class_id = Class.id + WHERE Student.class_id = "${id}" + `); + + return result[0]; + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 74d303a..cc9a7f0 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -2,18 +2,21 @@ import { Router } from "express"; import { ClassController } from "./controllers/ClassController"; import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; +import { GetClassInfoController } from "./controllers/GetClassInfoController"; const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); +const getClassInfoController = new GetClassInfoController(); router.put("/create-class", classController.create); router.put("/create-student", studentController.create); router.put("/create-teacher", teacherController.create); -router.get("/student/:id", studentController.show); +router.get("/students/:id", studentController.show); router.post("/teacher-class", teacherController.execute); -router.post("/student-class", studentController.execute); +router.post("/students-class", studentController.execute); +router.get("/students/class/:id", getClassInfoController.show); export { router }; From 1cdc929e678a0aa2d43b406d3e61e7421121605e Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Wed, 31 Mar 2021 12:29:12 -0300 Subject: [PATCH 20/30] Filtrar estudante por turma --- src/controllers/GetClassInfoController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/GetClassInfoController.ts b/src/controllers/GetClassInfoController.ts index fa3f9cb..e35ce16 100644 --- a/src/controllers/GetClassInfoController.ts +++ b/src/controllers/GetClassInfoController.ts @@ -13,7 +13,7 @@ class GetClassInfoController { const result = await selectStudentByClass(id); if (!result.length) { errorCode = 404; - throw new Error("Nenhum docente está na turma!"); + throw new Error("Nenhum estudante está na turma!"); } res.status(200).send({ message: result }); } catch (error) { From 5081f73bba35c89c92cb5fa40b23a7bf3ddcead4 Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Wed, 31 Mar 2021 13:11:28 -0300 Subject: [PATCH 21/30] Filtra estudantes por hobby --- src/controllers/StudentHobbyController.ts | 26 +++++++++++++++++++++++ src/models/selectStudentByHobby.ts | 16 ++++++++++++++ src/routes.ts | 4 +++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/controllers/StudentHobbyController.ts create mode 100644 src/models/selectStudentByHobby.ts diff --git a/src/controllers/StudentHobbyController.ts b/src/controllers/StudentHobbyController.ts new file mode 100644 index 0000000..398ac67 --- /dev/null +++ b/src/controllers/StudentHobbyController.ts @@ -0,0 +1,26 @@ +import { selectStudentByHobby } from "./../models/selectStudentByHobby"; +import { Request, Response } from "express"; + +class StudentHobbyController { + async show(req: Request, res: Response) { + let errorCode: number = 400; + try { + const hobby = req.query.hobby as string; + + if (!hobby) { + errorCode = 404; + throw new Error("Por favor digite um hobby!"); + } + const result = await selectStudentByHobby(hobby); + if (!result.length) { + errorCode = 404; + throw new Error("Não existe nenhum estudante relacionado a este hobby!"); + } + res.status(200).send({ message: result }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } +} + +export { StudentHobbyController }; diff --git a/src/models/selectStudentByHobby.ts b/src/models/selectStudentByHobby.ts new file mode 100644 index 0000000..359f5c0 --- /dev/null +++ b/src/models/selectStudentByHobby.ts @@ -0,0 +1,16 @@ +import connection from "../database/connection"; + +export const selectStudentByHobby = async (hobby: string): Promise => { + try { + const result = await connection.raw(` + SELECT hobby, id, name + FROM Student + WHERE hobby = '${hobby}' + GROUP BY hobby, id, name; + `); + + return result[0]; + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 434a750..70b5037 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -3,13 +3,14 @@ import { ClassController } from "./controllers/ClassController"; import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; import { GetClassInfoController } from "./controllers/GetClassInfoController"; - +import { StudentHobbyController } from "./controllers/StudentHobbyController"; const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); const getClassInfoController = new GetClassInfoController(); +const studentHobbyController = new StudentHobbyController(); router.put("/create-class", classController.create); @@ -18,6 +19,7 @@ router.get("/students/:id", studentController.show); router.post("/teacher-class", teacherController.execute); router.post("/students-class", studentController.execute); router.get("/students/class/:id", getClassInfoController.show); +router.get("/students", studentHobbyController.show); router.put("/teacher/create", teacherController.create); router.post("/teacher/class", teacherController.execute); From c14eb82db03ec1942cb65684bb5ab9afc28bf9ff Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Wed, 31 Mar 2021 13:58:32 -0300 Subject: [PATCH 22/30] Removendo classe do estudante --- src/controllers/GetClassInfoController.ts | 2 +- src/controllers/StudentController.ts | 16 ++++++++++++++++ src/models/removeStudentFromClass.ts | 19 +++++++++++++++++++ src/routes.ts | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/models/removeStudentFromClass.ts diff --git a/src/controllers/GetClassInfoController.ts b/src/controllers/GetClassInfoController.ts index e35ce16..e15b132 100644 --- a/src/controllers/GetClassInfoController.ts +++ b/src/controllers/GetClassInfoController.ts @@ -22,4 +22,4 @@ class GetClassInfoController { } } -export { GetClassInfoController }; +export { GetClassInfoController }; \ No newline at end of file diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index fbb3eb3..472a308 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -1,3 +1,4 @@ +import { removeStudentFromClass } from "./../models/removeStudentFromClass"; import { formatDate } from "./../utilities/verifiers"; import { insertStudent } from "./../models/insertStudent"; import { Request, Response } from "express"; @@ -63,6 +64,21 @@ class StudentController { res.status(errorCode).send({ message: error.message }); } } + + async update(req: Request, res: Response) { + let errorCode: number = 400; + try { + const id = req.params.id; + if (!id) { + errorCode = 422; + throw new Error("Informe o ID do estudante!"); + } + await removeStudentFromClass(id); + res.status(200).send({ message: "O aluno foi removido na turma" }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } } export { StudentController }; diff --git a/src/models/removeStudentFromClass.ts b/src/models/removeStudentFromClass.ts new file mode 100644 index 0000000..54b5513 --- /dev/null +++ b/src/models/removeStudentFromClass.ts @@ -0,0 +1,19 @@ +import connection from "../database/connection"; + +export const removeStudentFromClass = async (id: string): Promise => { + try { + await connection + .raw( + ` + UPDATE Student SET class_id = null WHERE id = "${id}" + ` + ) + .then((res) => { + console.log(res); + }); + } catch (error) { + console.log(error); + + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 70b5037..c1afbd6 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -20,6 +20,7 @@ router.post("/teacher-class", teacherController.execute); router.post("/students-class", studentController.execute); router.get("/students/class/:id", getClassInfoController.show); router.get("/students", studentHobbyController.show); +router.delete("/students/remove-class/:id", studentController.update); router.put("/teacher/create", teacherController.create); router.post("/teacher/class", teacherController.execute); From 5859ec46d2e546958a5ad308cd7d84521e79db7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 14:01:39 -0300 Subject: [PATCH 23/30] Removendo professor de uma turma --- src/controllers/TeacherController.ts | 18 ++++++++++++++++++ src/models/removeTeacher.ts | 11 +++++++++++ src/routes.ts | 1 + 3 files changed, 30 insertions(+) create mode 100644 src/models/removeTeacher.ts diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index 9a83ca9..63efbfc 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -1,6 +1,7 @@ import { Request, Response } from "express"; import { insertTeacher } from "../models/insertTeacher"; import { insertTeacherInClass } from "../models/insertTeacherInClass"; +import { removeTeacher } from "../models/removeTeacher"; import { selectTeachersFromClass } from "../models/selectTeachersFromClass"; import { checkDate, formatDate } from "../utilities/verifiers"; @@ -63,6 +64,23 @@ class TeacherController { res.status(errorCode).send({ message: error.message }); } } + + async update(req: Request, res: Response) { + let errorCode: number = 400; + try { + const { id } = req.params; + if (!id) { + errorCode = 404; + throw new Error( + "Insira um ID válido para a exclusão do professor da turma." + ); + } + await removeTeacher(id); + res.status(200).send({ message: "O professor for removido da turma." }); + } catch (error) { + res.status(error).send({ message: error.message }); + } + } } export { TeacherController }; diff --git a/src/models/removeTeacher.ts b/src/models/removeTeacher.ts new file mode 100644 index 0000000..76fc97c --- /dev/null +++ b/src/models/removeTeacher.ts @@ -0,0 +1,11 @@ +import connection from "../database/connection"; + +export const removeTeacher = async (id: string): Promise => { + try { + await connection.raw(` + UPDATE Teacher SET class_id=null WHERE id="${id}" + `); + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index 70b5037..da287af 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -24,5 +24,6 @@ router.get("/students", studentHobbyController.show); router.put("/teacher/create", teacherController.create); router.post("/teacher/class", teacherController.execute); router.get("/teacher/class/:id", teacherController.show); +router.delete("/teacher/class/delete/:id", teacherController.update); export { router }; From da9bf598bbc4be5a866c4c2337ee9a15d415710c Mon Sep 17 00:00:00 2001 From: DanielRatti Date: Wed, 31 Mar 2021 14:35:00 -0300 Subject: [PATCH 24/30] Remover o estudante --- src/controllers/StudentController.ts | 16 ++++++++++++++++ src/models/deleteStudent.ts | 9 +++++++++ src/routes.ts | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 src/models/deleteStudent.ts diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 472a308..6e22461 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -5,6 +5,7 @@ import { Request, Response } from "express"; import { checkDate } from "../utilities/verifiers"; import { selectStudentAgeById } from "../models/selectStudentAgeById"; import { insertStudentInClass } from "../models/insertStudentInClass"; +import { deleteStudent } from "../models/deleteStudent"; class StudentController { async create(req: Request, res: Response) { @@ -79,6 +80,21 @@ class StudentController { res.status(errorCode).send({ message: error.message }); } } + + async delete(req: Request, res: Response) { + let errorCode: number = 400; + try { + const id = req.params.id; + if (!id) { + errorCode = 422; + throw new Error("Informe o ID do estudante!"); + } + await deleteStudent(id); + res.status(200).send({ message: "O aluno foi removido!" }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } } export { StudentController }; diff --git a/src/models/deleteStudent.ts b/src/models/deleteStudent.ts new file mode 100644 index 0000000..205cb3d --- /dev/null +++ b/src/models/deleteStudent.ts @@ -0,0 +1,9 @@ +import connection from "../database/connection"; + +export const deleteStudent = async (id: string): Promise => { + try { + await connection.delete().from("Student").where({ id }); + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/routes.ts b/src/routes.ts index c1afbd6..c599e55 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -4,6 +4,7 @@ import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; import { GetClassInfoController } from "./controllers/GetClassInfoController"; import { StudentHobbyController } from "./controllers/StudentHobbyController"; + const router = Router(); const classController = new ClassController(); @@ -21,6 +22,7 @@ router.post("/students-class", studentController.execute); router.get("/students/class/:id", getClassInfoController.show); router.get("/students", studentHobbyController.show); router.delete("/students/remove-class/:id", studentController.update); +router.delete("/students/remove-student/:id", studentController.delete); router.put("/teacher/create", teacherController.create); router.post("/teacher/class", teacherController.execute); From 7c88617f7f86201c42e1a3d14f941955882de676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 15:31:59 -0300 Subject: [PATCH 25/30] =?UTF-8?q?Mudan=C3=A7a=20do=20modulo=20da=20turma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ClassController.ts | 20 ++++++++++++++++++++ src/controllers/GetClassInfoController.ts | 2 +- src/controllers/StudentController.ts | 4 ++-- src/controllers/TeacherController.ts | 4 ++-- src/models/changeClassModule.ts | 12 ++++++++++++ src/models/insertStudentInClass.ts | 13 +++++++++---- src/models/insertTeacher.ts | 1 - src/routes.ts | 10 +++++----- src/utilities/verifiers.ts | 1 - 9 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/models/changeClassModule.ts diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts index 7b707de..fda431d 100644 --- a/src/controllers/ClassController.ts +++ b/src/controllers/ClassController.ts @@ -1,4 +1,5 @@ import { Request, Response } from "express"; +import { changeClassModule } from "../models/changeClassModule"; import { insertClass } from "../models/insertClass"; import { checkDate, formatDate } from "../utilities/verifiers"; @@ -35,6 +36,25 @@ class ClassController { res.status(errorCode).send({ message: error.message }); } } + + async update(req: Request, res: Response) { + let errorCode: number = 404; + try { + const { id, module } = req.body; + if (!id || !module) { + errorCode = 422; + throw new Error( + "Preencha os campos do ID da turma e o número do módulo(1 a 7) para realizar a alteração." + ); + } + (await changeClassModule(id, module)) as string; + res + .status(200) + .send({ message: "O módulo da turma foi alterado com sucesso!" }); + } catch (error) { + res.status(errorCode).send({ message: error.message }); + } + } } export { ClassController }; diff --git a/src/controllers/GetClassInfoController.ts b/src/controllers/GetClassInfoController.ts index e15b132..e35ce16 100644 --- a/src/controllers/GetClassInfoController.ts +++ b/src/controllers/GetClassInfoController.ts @@ -22,4 +22,4 @@ class GetClassInfoController { } } -export { GetClassInfoController }; \ No newline at end of file +export { GetClassInfoController }; diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 6e22461..49b563a 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -75,7 +75,7 @@ class StudentController { throw new Error("Informe o ID do estudante!"); } await removeStudentFromClass(id); - res.status(200).send({ message: "O aluno foi removido na turma" }); + res.status(200).send({ message: "O aluno foi removido da turma" }); } catch (error) { res.status(errorCode).send({ message: error.message }); } @@ -90,7 +90,7 @@ class StudentController { throw new Error("Informe o ID do estudante!"); } await deleteStudent(id); - res.status(200).send({ message: "O aluno foi removido!" }); + res.status(200).send({ message: "O aluno foi removido do sistema." }); } catch (error) { res.status(errorCode).send({ message: error.message }); } diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index 63efbfc..da89175 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -76,9 +76,9 @@ class TeacherController { ); } await removeTeacher(id); - res.status(200).send({ message: "O professor for removido da turma." }); + res.status(200).send({ message: "O professor foi removido da turma." }); } catch (error) { - res.status(error).send({ message: error.message }); + res.status(errorCode).send({ message: error.message }); } } } diff --git a/src/models/changeClassModule.ts b/src/models/changeClassModule.ts new file mode 100644 index 0000000..ad15f7a --- /dev/null +++ b/src/models/changeClassModule.ts @@ -0,0 +1,12 @@ +import connection from "../database/connection"; + +export const changeClassModule = async ( + id: string, + module: string +): Promise => { + try { + await connection.raw(`UPDATE Class SET module=${module} WHERE id=${id}`); + } catch (error) { + throw new Error(error.message || error.sqlMessage); + } +}; diff --git a/src/models/insertStudentInClass.ts b/src/models/insertStudentInClass.ts index e81f368..3ea699b 100644 --- a/src/models/insertStudentInClass.ts +++ b/src/models/insertStudentInClass.ts @@ -2,13 +2,18 @@ import connection from "../database/connection"; export const insertStudentInClass = async ( class_id: string, - id:string + id: string ): Promise => { try { - await connection.raw(` + await connection + .raw( + ` UPDATE Student SET class_id = ${class_id} WHERE id = ${id} - `).then((res)=>{console.log(res); - }); + ` + ) + .then((res) => { + console.log(res); + }); } catch (error) { console.log(error); diff --git a/src/models/insertTeacher.ts b/src/models/insertTeacher.ts index 4645d48..e958696 100644 --- a/src/models/insertTeacher.ts +++ b/src/models/insertTeacher.ts @@ -17,7 +17,6 @@ export const insertTeacher = async ( }) .into("Teacher"); } catch (error) { - console.log(error.message || error.sqlMessage) throw new Error(error.message || error.sqlMessage); } }; diff --git a/src/routes.ts b/src/routes.ts index 667f7a4..344718e 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -13,12 +13,12 @@ const teacherController = new TeacherController(); const getClassInfoController = new GetClassInfoController(); const studentHobbyController = new StudentHobbyController(); -router.put("/create-class", classController.create); +router.put("/class/create", classController.create); +router.post("/class/update", classController.update); -router.put("/create-student", studentController.create); +router.put("/student/create", studentController.create); router.get("/students/:id", studentController.show); -router.post("/teacher-class", teacherController.execute); -router.post("/students-class", studentController.execute); +router.post("/students/class", studentController.execute); router.get("/students/class/:id", getClassInfoController.show); router.get("/students", studentHobbyController.show); router.delete("/students/remove-class/:id", studentController.update); @@ -27,6 +27,6 @@ router.delete("/students/remove-student/:id", studentController.delete); router.put("/teacher/create", teacherController.create); router.post("/teacher/class", teacherController.execute); router.get("/teacher/class/:id", teacherController.show); -router.delete("/teacher/class/delete/:id", teacherController.update); +router.delete("/teacher/class/remove/:id", teacherController.update); export { router }; diff --git a/src/utilities/verifiers.ts b/src/utilities/verifiers.ts index 180f0a0..697472c 100644 --- a/src/utilities/verifiers.ts +++ b/src/utilities/verifiers.ts @@ -1,5 +1,4 @@ export const formatDate = (date: string): string => { - const [day, month, year] = date.split("/"); return `${year}-${month}-${day}`; }; From 1da985057e8d886a3b8c305f4cbc5c136cf10816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 16:38:35 -0300 Subject: [PATCH 26/30] =?UTF-8?q?Mudan=C3=A7a=20na=20tabela=20de=20Class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ClassController.ts | 10 ++++++++-- src/database/migrations/createTables.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts index fda431d..d0b0c6f 100644 --- a/src/controllers/ClassController.ts +++ b/src/controllers/ClassController.ts @@ -10,9 +10,15 @@ class ClassController { const { name, start_date, end_date, module, type } = req.body; const checkingStartDate = checkDate(start_date); const checkingEndDate = checkDate(end_date); + let editName = name; + if (type === "Noturna") { + editName = (name as string) + "-na-night"; + } if (!name || !module || !type) { errorCode = 422; - throw new Error("Preencha corretamente os campos para a criação!"); + throw new Error( + "Preencha corretamente os campos de name, start_date, end_date, module e type!" + ); } if (!checkingStartDate) { errorCode = 406; @@ -25,7 +31,7 @@ class ClassController { const convertStartDate = formatDate(start_date); const convertEndDate = formatDate(end_date); (await insertClass( - name, + editName, convertStartDate, convertEndDate, module, diff --git a/src/database/migrations/createTables.ts b/src/database/migrations/createTables.ts index 94dd32d..f3ff3bd 100644 --- a/src/database/migrations/createTables.ts +++ b/src/database/migrations/createTables.ts @@ -9,7 +9,7 @@ const createTables = async (): Promise => { start_date DATE NOT NULL, end_date DATE NOT NULL, module ENUM ('1', '2', '3', '4', '5', '6', '7', '0') DEFAULT "0", - type ENUM ("full-time class", "-na-night") + type ENUM ("Integral", "Noturna") ); `); await connection.raw(` From cabc0ea2b87cb439f2fdea03e2de83c7f9890acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 17:14:49 -0300 Subject: [PATCH 27/30] Projeto finalizado --- src/controllers/ClassController.ts | 21 ++++++++++--------- ...foController.ts => ClassInfoController.ts} | 4 ++-- src/controllers/StudentController.ts | 7 ++++--- src/controllers/StudentHobbyController.ts | 4 +++- src/controllers/TeacherController.ts | 7 ++++--- src/models/insertClass.ts | 19 +++++++---------- src/models/insertStudent.ts | 17 +++++++-------- src/models/insertTeacher.ts | 16 ++++++-------- src/routes.ts | 4 ++-- src/types/class.ts | 7 +++++++ src/types/student.ts | 6 ++++++ src/types/teacher.ts | 6 ++++++ 12 files changed, 65 insertions(+), 53 deletions(-) rename src/controllers/{GetClassInfoController.ts => ClassInfoController.ts} (90%) create mode 100644 src/types/class.ts create mode 100644 src/types/student.ts create mode 100644 src/types/teacher.ts diff --git a/src/controllers/ClassController.ts b/src/controllers/ClassController.ts index d0b0c6f..8010c79 100644 --- a/src/controllers/ClassController.ts +++ b/src/controllers/ClassController.ts @@ -1,13 +1,20 @@ import { Request, Response } from "express"; import { changeClassModule } from "../models/changeClassModule"; import { insertClass } from "../models/insertClass"; +import { ClassInfo } from "../types/class"; import { checkDate, formatDate } from "../utilities/verifiers"; class ClassController { async create(req: Request, res: Response) { let errorCode: number = 404; try { - const { name, start_date, end_date, module, type } = req.body; + const { + name, + start_date, + end_date, + module, + type, + } = req.body as ClassInfo; const checkingStartDate = checkDate(start_date); const checkingEndDate = checkDate(end_date); let editName = name; @@ -28,15 +35,9 @@ class ClassController { errorCode = 406; throw new Error("Coloque a data final no formato DD/MM/YYYY"); } - const convertStartDate = formatDate(start_date); - const convertEndDate = formatDate(end_date); - (await insertClass( - editName, - convertStartDate, - convertEndDate, - module, - type - )) as string; + req.body.start_date = formatDate(start_date); + req.body.end_date = formatDate(end_date); + await insertClass(req.body); res.status(201).send({ message: "Turma criada com sucesso." }); } catch (error) { res.status(errorCode).send({ message: error.message }); diff --git a/src/controllers/GetClassInfoController.ts b/src/controllers/ClassInfoController.ts similarity index 90% rename from src/controllers/GetClassInfoController.ts rename to src/controllers/ClassInfoController.ts index e35ce16..0cb37e8 100644 --- a/src/controllers/GetClassInfoController.ts +++ b/src/controllers/ClassInfoController.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; import { selectStudentByClass } from "../models/selectStudentByClass"; -class GetClassInfoController { +class ClassInfoController { async show(req: Request, res: Response) { let errorCode: number = 400; try { @@ -22,4 +22,4 @@ class GetClassInfoController { } } -export { GetClassInfoController }; +export { ClassInfoController }; diff --git a/src/controllers/StudentController.ts b/src/controllers/StudentController.ts index 49b563a..8bfde87 100644 --- a/src/controllers/StudentController.ts +++ b/src/controllers/StudentController.ts @@ -6,12 +6,13 @@ import { checkDate } from "../utilities/verifiers"; import { selectStudentAgeById } from "../models/selectStudentAgeById"; import { insertStudentInClass } from "../models/insertStudentInClass"; import { deleteStudent } from "../models/deleteStudent"; +import { Student } from "../types/student"; class StudentController { async create(req: Request, res: Response) { let errorCode: number = 400; try { - const { name, email, birthdate, hobby } = req.body; + const { name, email, birthdate, hobby } = req.body as Student; if (!name || !email || !birthdate || !hobby) { errorCode = 422; @@ -25,8 +26,8 @@ class StudentController { errorCode = 406; throw new Error("Coloque uma data formato DD/MM/YYYY"); } - const formatingDate = formatDate(birthdate); - await insertStudent(name, email, formatingDate, hobby); + req.body.birthdate = formatDate(birthdate); + await insertStudent(req.body); res.status(201).send({ message: `Estudante ${name} adicionado a turma!`, }); diff --git a/src/controllers/StudentHobbyController.ts b/src/controllers/StudentHobbyController.ts index 398ac67..4aa4787 100644 --- a/src/controllers/StudentHobbyController.ts +++ b/src/controllers/StudentHobbyController.ts @@ -14,7 +14,9 @@ class StudentHobbyController { const result = await selectStudentByHobby(hobby); if (!result.length) { errorCode = 404; - throw new Error("Não existe nenhum estudante relacionado a este hobby!"); + throw new Error( + "Não existe nenhum estudante relacionado a este hobby!" + ); } res.status(200).send({ message: result }); } catch (error) { diff --git a/src/controllers/TeacherController.ts b/src/controllers/TeacherController.ts index da89175..66e4fa9 100644 --- a/src/controllers/TeacherController.ts +++ b/src/controllers/TeacherController.ts @@ -3,13 +3,14 @@ import { insertTeacher } from "../models/insertTeacher"; import { insertTeacherInClass } from "../models/insertTeacherInClass"; import { removeTeacher } from "../models/removeTeacher"; import { selectTeachersFromClass } from "../models/selectTeachersFromClass"; +import { Teacher } from "../types/teacher"; import { checkDate, formatDate } from "../utilities/verifiers"; class TeacherController { async create(req: Request, res: Response) { let errorCode: number = 400; try { - const { name, email, birthdate, speciality } = req.body; + const { name, email, birthdate, speciality } = req.body as Teacher; const checkingDate = checkDate(birthdate); if (!name || !email || !birthdate || !speciality) { errorCode = 422; @@ -21,8 +22,8 @@ class TeacherController { errorCode = 406; throw new Error("Coloque uma data formato DD/MM/YYYY"); } - const formatingDate = formatDate(birthdate); - await insertTeacher(name, email, formatingDate, speciality); + req.body.birthdate = formatDate(birthdate); + await insertTeacher(req.body); res.status(201).send({ message: "Docente criado com sucesso." }); } catch (error) { res.status(errorCode).send({ message: error.message }); diff --git a/src/models/insertClass.ts b/src/models/insertClass.ts index c4f581c..a097a46 100644 --- a/src/models/insertClass.ts +++ b/src/models/insertClass.ts @@ -1,21 +1,16 @@ import connection from "../database/connection"; +import { ClassInfo } from "../types/class"; -export const insertClass = async ( - name: string, - start_date: string, - end_date: string, - module: string, - type: string -): Promise => { +export const insertClass = async (classInfo: ClassInfo): Promise => { try { await connection .insert({ id: Date.now(), - name, - start_date, - end_date, - module, - type, + name: classInfo.name, + start_date: classInfo.start_date, + end_date: classInfo.end_date, + module: classInfo.module, + type: classInfo.module, }) .into("Class"); } catch (error) { diff --git a/src/models/insertStudent.ts b/src/models/insertStudent.ts index 5a58b7c..a98da63 100644 --- a/src/models/insertStudent.ts +++ b/src/models/insertStudent.ts @@ -1,18 +1,15 @@ +import { Student } from "../types/student"; import { connection } from "./../database/connection"; -export const insertStudent = async ( - name: string, - email: string, - birthdate: string, - hobby: string -): Promise => { + +export const insertStudent = async (student: Student): Promise => { try { await connection .insert({ id: Date.now(), - name: name, - email: email, - birthdate: birthdate, - hobby: hobby, + name: student.name, + email: student.email, + birthdate: student.birthdate, + hobby: student.hobby, }) .into("Student"); } catch (error) { diff --git a/src/models/insertTeacher.ts b/src/models/insertTeacher.ts index e958696..9f29da1 100644 --- a/src/models/insertTeacher.ts +++ b/src/models/insertTeacher.ts @@ -1,19 +1,15 @@ import connection from "../database/connection"; +import { Teacher } from "../types/teacher"; -export const insertTeacher = async ( - name: string, - email: string, - birthdate: string, - speciality: string -): Promise => { +export const insertTeacher = async (teacher: Teacher): Promise => { try { await connection .insert({ id: Date.now(), - name, - email, - birthdate, - speciality, + name: teacher.name, + email: teacher.email, + birthdate: teacher.birthdate, + speciality: teacher.speciality, }) .into("Teacher"); } catch (error) { diff --git a/src/routes.ts b/src/routes.ts index 344718e..820620e 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -2,7 +2,7 @@ import { Router } from "express"; import { ClassController } from "./controllers/ClassController"; import { StudentController } from "./controllers/StudentController"; import { TeacherController } from "./controllers/TeacherController"; -import { GetClassInfoController } from "./controllers/GetClassInfoController"; +import { ClassInfoController } from "./controllers/ClassInfoController"; import { StudentHobbyController } from "./controllers/StudentHobbyController"; const router = Router(); @@ -10,7 +10,7 @@ const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); -const getClassInfoController = new GetClassInfoController(); +const getClassInfoController = new ClassInfoController(); const studentHobbyController = new StudentHobbyController(); router.put("/class/create", classController.create); diff --git a/src/types/class.ts b/src/types/class.ts new file mode 100644 index 0000000..deac2a8 --- /dev/null +++ b/src/types/class.ts @@ -0,0 +1,7 @@ +export type ClassInfo = { + name: string; + start_date: string; + end_date: string; + module: string; + type: string; +}; diff --git a/src/types/student.ts b/src/types/student.ts new file mode 100644 index 0000000..b1dd3a5 --- /dev/null +++ b/src/types/student.ts @@ -0,0 +1,6 @@ +export type Student = { + name: string; + email: string; + birthdate: string; + hobby: string; +}; diff --git a/src/types/teacher.ts b/src/types/teacher.ts new file mode 100644 index 0000000..157d0cd --- /dev/null +++ b/src/types/teacher.ts @@ -0,0 +1,6 @@ +export type Teacher = { + name: string; + email: string; + birthdate: string; + speciality: string; +}; From eaa416fcedf2c9456d65cba685cb4a70c7ac994c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Victor=20T=2E=20Ferreira?= <74377057+josevictorsss@users.noreply.github.com> Date: Wed, 31 Mar 2021 17:23:14 -0300 Subject: [PATCH 28/30] Update README.md --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12ef622..daeb8a4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,20 @@ # LabenuSystem +## :memo: Funcionalidades +* Criar estudante +* Criar docente +* Criar turma +* Adicionar estudante a turma +* Adicionar docente a turma +* Pegar a idade de algum estudante a partir do ID +* Exibir estudantes de uma turma +* Exibir docentes de uma turma +* Exibir estudantes que possuam o mesmo hobby +* Remover estudante de uma turma +* Remover estudante +* Remover docente de uma turma +* Mudar turma de módulo + ## 💻 Documentação Teste as rotas com a documentação, basta importar ela para seu postman. @@ -19,12 +34,23 @@ Esse projeto foi desenvolvido com as seguintes tecnologias: ## 🚀 Como executar * Clone o repositório ``` - $https://github.com/future4code/epps-labenu-system6.git +$https://github.com/future4code/epps-labenu-system6.git ``` * Instale as dependências com ``` npm install ``` +* Crie um arquivo .env +``` +touch .env + ``` +* Preencha o arquivo .env +``` +DB_HOST = Coloque aqui seu endereço do banco de dados +DB_USER = Coloque aqui seu usuário +DB_PASSWORD = Coloque aqui sua senha +DB_SCHEMA = Coloque aqui o nome do banco de dados + ``` * Crie as tabelas com ``` npm run table From 7402d31d0e0d093326f7f3f33cfcd94cf07a1ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Victor=20T=2E=20Ferreira?= <74377057+josevictorsss@users.noreply.github.com> Date: Wed, 31 Mar 2021 18:19:50 -0300 Subject: [PATCH 29/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index daeb8a4..e5745f3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ ## 💻 Documentação Teste as rotas com a documentação, basta importar ela para seu postman. -[Postman - LabenuSystem]() +[Postman - LabenuSystem](https://documenter.getpostman.com/view/14145831/TzCMeTwk#a0cffc9e-31bf-48a6-94c5-573cdfa24464) ## ✨ Tecnologias Esse projeto foi desenvolvido com as seguintes tecnologias: From 911cb87b8a4e2a706db79b887d3a13b37bd1ad41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9?= Date: Wed, 31 Mar 2021 18:24:02 -0300 Subject: [PATCH 30/30] =?UTF-8?q?Mudan=C3=A7a=20no=20nome=20do=20controlle?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes.ts b/src/routes.ts index 820620e..6af8ea6 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -10,7 +10,7 @@ const router = Router(); const classController = new ClassController(); const studentController = new StudentController(); const teacherController = new TeacherController(); -const getClassInfoController = new ClassInfoController(); +const classInfoController = new ClassInfoController(); const studentHobbyController = new StudentHobbyController(); router.put("/class/create", classController.create); @@ -19,7 +19,7 @@ router.post("/class/update", classController.update); router.put("/student/create", studentController.create); router.get("/students/:id", studentController.show); router.post("/students/class", studentController.execute); -router.get("/students/class/:id", getClassInfoController.show); +router.get("/students/class/:id", classInfoController.show); router.get("/students", studentHobbyController.show); router.delete("/students/remove-class/:id", studentController.update); router.delete("/students/remove-student/:id", studentController.delete);