Skip to content

Commit

Permalink
método create e delete Learning Path
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskisoba committed Nov 19, 2023
1 parent 5a95362 commit 5204dbd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/ElectiveControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Electives } = require('../models/schemas')

exports.createElective = async(req, res) => {
const { name, description, school_year, teacher, vacancies, schedules } = req.body

await Electives.create({
name: name,
description: description,
Expand Down
30 changes: 30 additions & 0 deletions backend/controllers/LearningPathsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { LearningPath } = require('../models/schemas')

exports.createLearningPaths = async(req, res) => {
const { name, description, school_year, electives} = req.body
let electives_object = JSON.stringify(electives)

await LearningPath.create({
name: name,
description: description,
school_year: school_year,
electives: electives_object
}).then(() => {
res.status(201).json("OK")
}).catch((err) => {
if(err){
res.status(400).json({error: err})
}
})
}

exports.deleteLearningPaths = async(req, res) => {
const { id } = req.body
await LearningPath.destroy({ where: {id: id}}).then(() => {
res.status(200).json("OK")
}).catch((err) => {
if(err){
res.status(400).json({error: err})
}
})
}
4 changes: 4 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ const database = require('./models/schemas');
const port = 3001;
const userRoute = require('./views/routes/Users');
const electiveRoute = require('./views/routes/Electives')
const learningPathRoute = require('./views/routes/LearningPaths')
app.use(express.json());
//ajustar rotas
app.use(userRoute);
app.use(electiveRoute);
app.use(learningPathRoute);

database.sequelize.sync().then(() => {
app.listen(port, () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/migrations/learning_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
ds_name: { type: Sequelize. STRING(40), allowNull: false },
ds_description: { type: Sequelize.STRING(150),allowNull: false },
ds_school_year: { type: Sequelize.INTEGER, allowNull: false },
ds_electives: { type: Sequelize.JSON, allowNull: false}
ds_electives: { type: Sequelize.TEXT, allowNull: false}
})

await transaction.commit()
Expand Down
6 changes: 3 additions & 3 deletions backend/models/schemas/LearningPaths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = (sequelize, DataTypes) => {
const LearningPaths = sequelize.define("LearningPaths", {
const LearningPath = sequelize.define("LearningPath", {
id: {
type: DataTypes.INTEGER,
field: "co_learning_paths",
Expand All @@ -23,11 +23,11 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false
},
electives: {
type: DataTypes.JSON,
type: DataTypes.TEXT,
field: "ds_electives",
allowNull: false
}
})

return LearningPaths;
return LearningPath;
}
8 changes: 8 additions & 0 deletions backend/views/routes/LearningPaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
const learningPathsController = require('../../controllers/LearningPathsController')

router.post("/learning_paths/createLearningPaths", learningPathsController.createLearningPaths);
router.delete("/learning_paths/", learningPathsController.deleteLearningPaths)

module.exports = router;

0 comments on commit 5204dbd

Please sign in to comment.