Skip to content

Commit

Permalink
[FIX]: erro no cadastro de usuários
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaryoshida committed Nov 22, 2023
1 parent 8fbc758 commit 9ebdd53
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 51 deletions.
23 changes: 0 additions & 23 deletions backend/config/config.js

This file was deleted.

22 changes: 10 additions & 12 deletions backend/controllers/ElectiveControllers.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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})
}
})
}
res.status(400).json({error: err});
};
});
};
22 changes: 11 additions & 11 deletions backend/controllers/LearningPathsController.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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})
}
})
}
res.status(400).json({error: err});
};
});
};
7 changes: 5 additions & 2 deletions backend/controllers/middlewares/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!' });
Expand All @@ -26,5 +31,3 @@ const validateToken = (req, res, next) => {

module.exports = { createToken, validateToken };


module.exports = { createToken, validateToken };
2 changes: 1 addition & 1 deletion backend/views/routes/Electives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion backend/views/routes/LearningPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion backend/views/routes/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 9ebdd53

Please sign in to comment.