registrar alumno tercer grado

This commit is contained in:
Lemuel Marquez
2021-07-11 00:51:16 -05:00
parent e092a7742f
commit db18585f64
3 changed files with 37 additions and 2 deletions
+1 -2
View File
@@ -1,4 +1,3 @@
const { Op } = require('sequelize');
const { validarNumeroCuenta } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
@@ -14,7 +13,7 @@ const get = async (body) => {
}).then((res) => {
if (!res) throw new Error('No existe esta alumno.');
if (res.deseaAsistir)
throw new Error('Ta se registro a este alumno al recorrido.');
throw new Error('Ya se registro a este alumno al recorrido.');
delete res.dataValues.idGrupo;
delete res.dataValues.Grupo.dataValues.idCarrera;
return res;
@@ -0,0 +1,23 @@
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const TercerSemestre = require(`${dbPath}/TercerSemestre`);
const get = async (body) => {
const idTercerSemestre = validarId(body.idTercerSemestre);
return TercerSemestre.findOne({ where: { idTercerSemestre } })
.then((res) => {
if (!res) throw new Error('No existe esta alumno.');
if (res.deseaAsistir)
throw new Error('Ya se registro a este alumno al recorrido.');
return TercerSemestre.update(
{ deseaAsistir: true },
{ where: { idTercerSemestre } }
);
})
.then((res) => ({
message: 'Se ha registrado correctamente al alumno al recorrido.',
}));
};
module.exports = get;
+13
View File
@@ -3,7 +3,20 @@ const app = express();
const route = '/tercer_semestre';
const controllerPath = '../controller/TercerSemestre';
const get = require(`${controllerPath}/get`);
const registrar = require(`${controllerPath}/registrar`);
//PUT
app.put(`${route}/registrar`, (req, res) => {
return registrar(req.body)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
// GET
app.get(`${route}`, (req, res) => {
return get(req.query)
.then((data) => {