registrar alumno tercer grado
This commit is contained in:
@@ -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;
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user