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 } }