get carrera horario

This commit is contained in:
Lemuel Marquez
2021-07-11 23:29:35 -05:00
parent 770db9e486
commit ff462be168
4 changed files with 53 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
const { Op, json } = require('sequelize');
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
const Horario = require(`${dbPath}/Horario`);
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
const get = async (body) => {
const idCarrera = validarId(body.idCarrera);
return Carrera.findOne({ where: { idCarrera } })
.then((res) => {
if (!res) throw new Error('No existe esta carrera.');
return CarreraHorario.findAll({
where: { idCarrera },
include: [{ model: Horario }],
});
})
.then(async (res) => {
const data = [];
for (let i = 0; i < res.length; i++) {
let lugaresOcupados = await PrimerSemestre.findAll({
where: { idHorario: res[i].Horario.idHorario },
}).then((res) => res.length);
if (lugaresOcupados < 50)
data.push({ Horario: res[i].Horario, lugares: 50 - lugaresOcupados });
}
return data;
});
};
module.exports = get;
-3
View File
@@ -30,9 +30,6 @@ const get = async (body) => {
.then((res) => {
delete res.dataValues.idHorario;
delete res.dataValues.idGrupo;
res.dataValues.Horario.dataValues.horario = moment(
res.Horario.horario
).format();
return { alumnoTercerSemestre, GrupoHorario: res };
});
};
+17
View File
@@ -0,0 +1,17 @@
const express = require('express');
const app = express();
const route = '/carrera_horario';
const controllerPath = '../controller/CarreraHorario';
const get = require(`${controllerPath}/get`);
app.get(`${route}`, (req, res) => {
return get(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
module.exports = app;
+1
View File
@@ -2,6 +2,7 @@ const express = require('express');
const app = express();
app.use(require('./Carrera'));
app.use(require('./CarreraHorario'));
app.use(require('./Grupo'));
app.use(require('./TercerSemestre'));