From f4c543fb16df78e21c55b73bb40d6f65df113b0f Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 10:35:01 -0500 Subject: [PATCH] horarios dia! --- server/controller/CarreraHorario/get.js | 1 - .../controller/CarreraHorario/horariosDia.js | 25 +++++++++++++++++++ .../controller/PrimerSemestre/asistencia.js | 10 +++++++- server/routes/CarreraHorario.js | 11 ++++++++ server/routes/PrimerSemestre.js | 22 ++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 server/controller/CarreraHorario/horariosDia.js diff --git a/server/controller/CarreraHorario/get.js b/server/controller/CarreraHorario/get.js index 8d8acfa..5b2894c 100644 --- a/server/controller/CarreraHorario/get.js +++ b/server/controller/CarreraHorario/get.js @@ -1,4 +1,3 @@ -const moment = require('moment'); const { validarId } = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); diff --git a/server/controller/CarreraHorario/horariosDia.js b/server/controller/CarreraHorario/horariosDia.js new file mode 100644 index 0000000..a554e1b --- /dev/null +++ b/server/controller/CarreraHorario/horariosDia.js @@ -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; diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index ed82c61..f167b56 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -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 } } diff --git a/server/routes/CarreraHorario.js b/server/routes/CarreraHorario.js index 9298847..3755bec 100644 --- a/server/routes/CarreraHorario.js +++ b/server/routes/CarreraHorario.js @@ -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) => { diff --git a/server/routes/PrimerSemestre.js b/server/routes/PrimerSemestre.js index a3760d1..5255eed 100644 --- a/server/routes/PrimerSemestre.js +++ b/server/routes/PrimerSemestre.js @@ -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;