horarios dia!

This commit is contained in:
Lemuel Marquez
2021-07-21 10:35:01 -05:00
parent 666a29cc72
commit f4c543fb16
5 changed files with 67 additions and 2 deletions
-1
View File
@@ -1,4 +1,3 @@
const moment = require('moment');
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
@@ -0,0 +1,25 @@
const moment = require('moment');
const dbPath = '../../db/tablas';
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
const Horario = require(`${dbPath}/Horario`);
const hoy = moment().add(13, 'd');
const horariosDia = async (body) => {
return CarreraHorario.findAll({
include: [{ model: Horario }],
order: ['idHorario'],
}).then(async (res) => {
const data = [];
for (let i = 0; i < res.length; i++) {
const fecha = moment(res[i].Horario.horario);
if (hoy.dayOfYear() === fecha.dayOfYear()) {
data.push({ Horario: res[i].Horario });
}
}
return data;
});
};
module.exports = horariosDia;
@@ -1,16 +1,24 @@
const moment = require('moment');
const helperPath = '../../helper';
const validar = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const Horario = require(`${dbPath}/Horario`);
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
const asistencia = async (body) => {
const idPrimerSemestre = validar.validarId(body.idPrimerSemestre);
return PrimerSemestre.findOne({ where: { idPrimerSemestre } })
return PrimerSemestre.findOne({
where: { idPrimerSemestre },
include: [{ model: Horario }],
})
.then((res) => {
if (!res) throw new Error('No existe este alumno.');
if (res.asistio)
throw new Error('Ya fue registrada la asistencia de este alumno.');
/*
Validar que sea el dia del recorrido
*/
return PrimerSemestre.update(
{ asistio: true },
{ where: { idPrimerSemestre } }
+11
View File
@@ -3,6 +3,7 @@ const app = express();
const route = '/carrera_horario';
const controllerPath = '../controller/CarreraHorario';
const get = require(`${controllerPath}/get`);
const horariosDia = require(`${controllerPath}/horariosDia`);
const monitor = require(`${controllerPath}/monitor`);
// GET
@@ -16,6 +17,16 @@ app.get(`${route}`, (req, res) => {
});
});
app.get(`${route}/horarios_dia`, (req, res) => {
return horariosDia(req.body)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
app.get(`${route}/monitor`, (req, res) => {
return monitor(req.body)
.then((data) => {
+22
View File
@@ -3,6 +3,8 @@ const app = express();
const route = '/primer_semestre';
const controllerPath = '../controller/PrimerSemestre';
const csv = require(`${controllerPath}/csv`);
const asistencia = require(`${controllerPath}/asistencia`);
const asistentes = require(`${controllerPath}/asistentes`);
const registrar = require(`${controllerPath}/registrar`);
// POST
@@ -26,6 +28,26 @@ app.post(`${route}/registrar`, (req, res) => {
});
});
// PUT
app.put(`${route}/asistencia`, (req, res) => {
return asistencia(req.body)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
// GET
app.put(`${route}/asistentes`, (req, res) => {
return asistentes(req.query)
.then((data) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
module.exports = app;