diff --git a/backend/controllers/ElectiveControllers.js b/backend/controllers/ElectiveControllers.js index 033546e1..34db7430 100644 --- a/backend/controllers/ElectiveControllers.js +++ b/backend/controllers/ElectiveControllers.js @@ -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, diff --git a/backend/controllers/LearningPathsController.js b/backend/controllers/LearningPathsController.js new file mode 100644 index 00000000..6288c2c5 --- /dev/null +++ b/backend/controllers/LearningPathsController.js @@ -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}) + } + }) +} \ No newline at end of file diff --git a/backend/index.js b/backend/index.js index 27e43a84..7a32d0c9 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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, () => { diff --git a/backend/migrations/learning_paths.js b/backend/migrations/learning_paths.js index 454c62af..690f5663 100644 --- a/backend/migrations/learning_paths.js +++ b/backend/migrations/learning_paths.js @@ -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() diff --git a/backend/models/schemas/LearningPaths.js b/backend/models/schemas/LearningPaths.js index 503b8b56..bc4f7e72 100644 --- a/backend/models/schemas/LearningPaths.js +++ b/backend/models/schemas/LearningPaths.js @@ -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", @@ -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; } \ No newline at end of file diff --git a/backend/views/routes/LearningPaths.js b/backend/views/routes/LearningPaths.js new file mode 100644 index 00000000..fb0f2e7c --- /dev/null +++ b/backend/views/routes/LearningPaths.js @@ -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;