-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc0164d
commit 35eb228
Showing
8 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { LearningPathsEnrolment } = require('../models/schemas'); | ||
|
||
exports.studentEnrolment = async (req, res) => { | ||
const { learning_path_id, student_id } = req.body; | ||
const existingEnrolment = await LearningPathsEnrolment.findOne({where: {learning_path_id: learning_path_id, student_id: student_id} }); | ||
|
||
if (existingEnrolment) { | ||
return res.status(400).json({error: 'O aluno já está matriculado nesta trilha.'}); | ||
} else { | ||
await LearningPathsEnrolment.create({ | ||
learning_path_id: learning_path_id, | ||
student_id: student_id, | ||
}).then(() => { | ||
res.status(201).json("Solicitação bem sucedida") | ||
}).catch((err) => { | ||
if(err){ | ||
res.status(400).json({error: err.message || 'Erro desconhecido durante a matrícula.'}); | ||
}; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const LearningPathsEnrolment = sequelize.define("LearningPathsEnrolment", { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
field: "id", | ||
primaryKey: true, | ||
autoIncrement: true | ||
}, | ||
learning_path_id: { | ||
type: DataTypes.INTEGER, | ||
field: "learning_path_id", | ||
allowNull: false, | ||
}, | ||
student_id: { | ||
type: DataTypes.INTEGER, | ||
field: "student_id", | ||
allowNull: false, | ||
}, | ||
}) | ||
|
||
return LearningPathsEnrolment; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const learningPathsEnrolmentController = require('../../controllers/LearningPathsEnrolmentController'); | ||
|
||
|
||
router.post('/studentenrolment', learningPathsEnrolmentController.studentEnrolment); | ||
|
||
module.exports = router; |