From 9ebdd537935ee1e1445a4a33cc8b35309f9ae715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Yoshida?= Date: Tue, 21 Nov 2023 21:22:40 -0300 Subject: [PATCH] =?UTF-8?q?[FIX]:=20erro=20no=20cadastro=20de=20usu=C3=A1r?= =?UTF-8?q?ios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config/config.js | 23 ------------------- backend/controllers/ElectiveControllers.js | 22 ++++++++---------- .../controllers/LearningPathsController.js | 22 +++++++++--------- backend/controllers/middlewares/Auth.js | 7 ++++-- backend/views/routes/Electives.js | 2 +- backend/views/routes/LearningPaths.js | 2 +- backend/views/routes/Users.js | 2 +- 7 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 backend/config/config.js diff --git a/backend/config/config.js b/backend/config/config.js deleted file mode 100644 index 8cad812b..00000000 --- a/backend/config/config.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = { - "development": { - "username": process.env.DB_USERNAME, - "password": process.env.DB_PASSWORD, - "database":process.env.DB_NAME, - "host": "127.0.0.1", - "dialect": "mysql" - }, - "test": { - "username": "root", - "password": null, - "database": "database_test", - "host": "127.0.0.1", - "dialect": "mysql" - }, - "production": { - "username": "root", - "password": null, - "database": "database_production", - "host": "127.0.0.1", - "dialect": "mysql" - } -} diff --git a/backend/controllers/ElectiveControllers.js b/backend/controllers/ElectiveControllers.js index 34db7430..25a8a9e3 100644 --- a/backend/controllers/ElectiveControllers.js +++ b/backend/controllers/ElectiveControllers.js @@ -1,9 +1,7 @@ const { Electives } = require('../models/schemas') - exports.createElective = async(req, res) => { - const { name, description, school_year, teacher, vacancies, schedules } = req.body - + const { name, description, school_year, teacher, vacancies, schedules } = req.body; await Electives.create({ name: name, description: description, @@ -15,18 +13,18 @@ exports.createElective = async(req, res) => { res.status(201).json("OK") }).catch((err) => { if(err){ - res.status(400).json({error: err}) - } - }) -} + res.status(400).json({error: err}); + }; + }); +}; exports.deleteElective = async(req, res) => { const { id } = req.body await Electives.destroy({ where: {id: id}}).then(() => { - res.status(200).json("OK") + res.status(200).json("OK"); }).catch((err) => { if(err){ - res.status(400).json({error: err}) - } - }) -} \ No newline at end of file + res.status(400).json({error: err}); + }; + }); +}; \ No newline at end of file diff --git a/backend/controllers/LearningPathsController.js b/backend/controllers/LearningPathsController.js index 6288c2c5..277bb464 100644 --- a/backend/controllers/LearningPathsController.js +++ b/backend/controllers/LearningPathsController.js @@ -1,8 +1,8 @@ const { LearningPath } = require('../models/schemas') exports.createLearningPaths = async(req, res) => { - const { name, description, school_year, electives} = req.body - let electives_object = JSON.stringify(electives) + const { name, description, school_year, electives} = req.body; + let electives_object = JSON.stringify(electives); await LearningPath.create({ name: name, @@ -14,17 +14,17 @@ exports.createLearningPaths = async(req, res) => { }).catch((err) => { if(err){ res.status(400).json({error: err}) - } - }) -} + }; + }); +}; exports.deleteLearningPaths = async(req, res) => { - const { id } = req.body + const { id } = req.body; await LearningPath.destroy({ where: {id: id}}).then(() => { - res.status(200).json("OK") + res.status(200).json("OK"); }).catch((err) => { if(err){ - res.status(400).json({error: err}) - } - }) -} \ No newline at end of file + res.status(400).json({error: err}); + }; + }); +}; \ No newline at end of file diff --git a/backend/controllers/middlewares/Auth.js b/backend/controllers/middlewares/Auth.js index 785bf223..c40a4c7f 100644 --- a/backend/controllers/middlewares/Auth.js +++ b/backend/controllers/middlewares/Auth.js @@ -8,6 +8,11 @@ const createToken = (user) => { }; const validateToken = (req, res, next) => { + + if (req.path === '/register' && req.method === 'POST') { + return next(); + } + const accessToken = req.cookies && req.cookies['access-token']; if (!accessToken) { return res.status(400).json({ error: 'Usuário não autenticado!' }); @@ -26,5 +31,3 @@ const validateToken = (req, res, next) => { module.exports = { createToken, validateToken }; - -module.exports = { createToken, validateToken }; diff --git a/backend/views/routes/Electives.js b/backend/views/routes/Electives.js index 07dbf7d7..55b9005a 100644 --- a/backend/views/routes/Electives.js +++ b/backend/views/routes/Electives.js @@ -3,6 +3,6 @@ const router = express.Router(); const electivesController = require('../../controllers/ElectiveControllers') router.post("/createElective", electivesController.createElective); -router.delete("/", electivesController.deleteElective) +router.delete("/deleteElective", electivesController.deleteElective) module.exports = router; diff --git a/backend/views/routes/LearningPaths.js b/backend/views/routes/LearningPaths.js index 75c075c3..51588998 100644 --- a/backend/views/routes/LearningPaths.js +++ b/backend/views/routes/LearningPaths.js @@ -3,6 +3,6 @@ const router = express.Router(); const learningPathsController = require('../../controllers/LearningPathsController') router.post("/createLearningPaths", learningPathsController.createLearningPaths); -router.delete("/", learningPathsController.deleteLearningPaths) +router.delete("/deleteLearningPaths", learningPathsController.deleteLearningPaths) module.exports = router; diff --git a/backend/views/routes/Users.js b/backend/views/routes/Users.js index 544d685a..a57d9e6c 100644 --- a/backend/views/routes/Users.js +++ b/backend/views/routes/Users.js @@ -5,7 +5,7 @@ const userController = require('../../controllers/UserControllers'); const { validateToken } = require('../../controllers/middlewares/Auth'); router.use(cookieParser()); -router.post('/', userController.userRegister); +router.post('/register', userController.userRegister); router.post('/login', userController.userLogin); router.get('/profile', validateToken, (req, res) => {