From 666a29cc729ae2f6ee8b7039b8a4cc464937fec5 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 09:07:59 -0500 Subject: [PATCH 1/9] monitor, asistencia, asistentes --- .../graficas.js => CarreraHorario/monitor.js} | 10 ++------ .../controller/PrimerSemestre/asistencia.js | 24 +++++++++++++++++++ .../controller/PrimerSemestre/asistentes.js | 17 +++++++++++++ server/controller/PrimerSemestre/csv.js | 6 ++--- server/controller/PrimerSemestre/registrar.js | 4 ++-- .../controller/TercerSemestre/asistencia.js | 0 .../controller/TercerSemestre/asistentes.js | 0 server/controller/TercerSemestre/monitor.js | 0 server/routes/CarreraHorario.js | 12 ++++++++++ server/routes/PrimerSemestre.js | 10 -------- 10 files changed, 60 insertions(+), 23 deletions(-) rename server/controller/{PrimerSemestre/graficas.js => CarreraHorario/monitor.js} (69%) create mode 100644 server/controller/PrimerSemestre/asistencia.js create mode 100644 server/controller/PrimerSemestre/asistentes.js create mode 100644 server/controller/TercerSemestre/asistencia.js create mode 100644 server/controller/TercerSemestre/asistentes.js create mode 100644 server/controller/TercerSemestre/monitor.js diff --git a/server/controller/PrimerSemestre/graficas.js b/server/controller/CarreraHorario/monitor.js similarity index 69% rename from server/controller/PrimerSemestre/graficas.js rename to server/controller/CarreraHorario/monitor.js index 8384268..87a33dc 100644 --- a/server/controller/PrimerSemestre/graficas.js +++ b/server/controller/CarreraHorario/monitor.js @@ -1,16 +1,10 @@ -const moment = require('moment'); -const { Op } = require('sequelize'); -const helperPath = '../../helper'; -const helper = require(`${helperPath}/helper`); -const encriptar = require(`${helperPath}/encriptar`); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); const CarreraHorario = require(`${dbPath}/CarreraHorario`); -const Grupo = require(`${dbPath}/Grupo`); const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const get = async (body) => { +const monitor = async (body) => { return CarreraHorario.findAll({ include: [{ model: Horario }, { model: Carrera }], order: ['idHorario'], @@ -28,4 +22,4 @@ const get = async (body) => { }); }; -module.exports = get; +module.exports = monitor; diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js new file mode 100644 index 0000000..ed82c61 --- /dev/null +++ b/server/controller/PrimerSemestre/asistencia.js @@ -0,0 +1,24 @@ +const helperPath = '../../helper'; +const validar = require(`${helperPath}/validar`); +const dbPath = '../../db/tablas'; +const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); + +const asistencia = async (body) => { + const idPrimerSemestre = validar.validarId(body.idPrimerSemestre); + + return PrimerSemestre.findOne({ where: { idPrimerSemestre } }) + .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.'); + return PrimerSemestre.update( + { asistio: true }, + { where: { idPrimerSemestre } } + ); + }) + .then((res) => ({ + message: 'Se registro correctamente la asistencia de este alumno.', + })); +}; + +module.exports = asistencia; diff --git a/server/controller/PrimerSemestre/asistentes.js b/server/controller/PrimerSemestre/asistentes.js new file mode 100644 index 0000000..9248a3a --- /dev/null +++ b/server/controller/PrimerSemestre/asistentes.js @@ -0,0 +1,17 @@ +const helperPath = '../../helper'; +const validar = require(`${helperPath}/validar`); +const dbPath = '../../db/tablas'; +const Carrera = require(`${dbPath}/Carrera`); +const Grupo = require(`${dbPath}/Grupo`); +const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); + +const asistentes = async (body) => { + const idHorario = validar.validarId(body.idHorario); + + return PrimerSemestre.findAll({ + where: { idHorario }, + include: [{ model: Grupo, include: [{ model: Carrera }] }], + }); +}; + +module.exports = asistentes; diff --git a/server/controller/PrimerSemestre/csv.js b/server/controller/PrimerSemestre/csv.js index e109480..322392a 100644 --- a/server/controller/PrimerSemestre/csv.js +++ b/server/controller/PrimerSemestre/csv.js @@ -1,5 +1,5 @@ -const { convertArrayToCSV } = require('convert-array-to-csv'); const moment = require('moment'); +const { convertArrayToCSV } = require('convert-array-to-csv'); const helperPath = '../../helper'; const helper = require(`${helperPath}/helper`); const encriptar = require(`${helperPath}/encriptar`); @@ -9,7 +9,7 @@ const Grupo = require(`${dbPath}/Grupo`); const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const get = async (body) => { +const csv = async (body) => { const path = `server/uploads/primer_semestre.csv`; const data = []; @@ -54,4 +54,4 @@ const get = async (body) => { .then((res) => path); }; -module.exports = get; +module.exports = csv; diff --git a/server/controller/PrimerSemestre/registrar.js b/server/controller/PrimerSemestre/registrar.js index 8bcc1a2..e0c7b5c 100644 --- a/server/controller/PrimerSemestre/registrar.js +++ b/server/controller/PrimerSemestre/registrar.js @@ -9,7 +9,7 @@ const Horario = require(`${dbPath}/Horario`); const Grupo = require(`${dbPath}/Grupo`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const get = async (body) => { +const registrar = async (body) => { const idCarrera = validar.validarId(body.idCarrera); const idGrupo = validar.validarId(body.idGrupo); const idHorario = validar.validarId(body.idHorario); @@ -82,4 +82,4 @@ const get = async (body) => { })); }; -module.exports = get; +module.exports = registrar; diff --git a/server/controller/TercerSemestre/asistencia.js b/server/controller/TercerSemestre/asistencia.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/TercerSemestre/asistentes.js b/server/controller/TercerSemestre/asistentes.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/TercerSemestre/monitor.js b/server/controller/TercerSemestre/monitor.js new file mode 100644 index 0000000..e69de29 diff --git a/server/routes/CarreraHorario.js b/server/routes/CarreraHorario.js index ba647f1..9298847 100644 --- a/server/routes/CarreraHorario.js +++ b/server/routes/CarreraHorario.js @@ -3,7 +3,9 @@ const app = express(); const route = '/carrera_horario'; const controllerPath = '../controller/CarreraHorario'; const get = require(`${controllerPath}/get`); +const monitor = require(`${controllerPath}/monitor`); +// GET app.get(`${route}`, (req, res) => { return get(req.query) .then((data) => { @@ -14,4 +16,14 @@ app.get(`${route}`, (req, res) => { }); }); +app.get(`${route}/monitor`, (req, res) => { + return monitor(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + module.exports = app; diff --git a/server/routes/PrimerSemestre.js b/server/routes/PrimerSemestre.js index c62403f..a3760d1 100644 --- a/server/routes/PrimerSemestre.js +++ b/server/routes/PrimerSemestre.js @@ -3,7 +3,6 @@ const app = express(); const route = '/primer_semestre'; const controllerPath = '../controller/PrimerSemestre'; const csv = require(`${controllerPath}/csv`); -const graficas = require(`${controllerPath}/graficas`); const registrar = require(`${controllerPath}/registrar`); // POST @@ -28,14 +27,5 @@ app.post(`${route}/registrar`, (req, res) => { }); // GET -app.get(`${route}/graficas`, (req, res) => { - return graficas(req.body) - .then((data) => { - res.status(200).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); module.exports = app; From f4c543fb16df78e21c55b73bb40d6f65df113b0f Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 10:35:01 -0500 Subject: [PATCH 2/9] 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; From 952dfb03ff327e89afd68cdea348159cd3dedd58 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 10:46:35 -0500 Subject: [PATCH 3/9] validacion asistencia dia correcto --- .../monitor.js => GrupoHorario.js/horariosDIa.js} | 0 server/controller/GrupoHorario.js/monitor.js | 0 server/controller/PrimerSemestre/asistencia.js | 6 +++--- server/controller/TercerSemestre/csv.js | 4 ++-- server/controller/TercerSemestre/registrar.js | 4 ++-- server/routes/PrimerSemestre.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename server/controller/{TercerSemestre/monitor.js => GrupoHorario.js/horariosDIa.js} (100%) create mode 100644 server/controller/GrupoHorario.js/monitor.js diff --git a/server/controller/TercerSemestre/monitor.js b/server/controller/GrupoHorario.js/horariosDIa.js similarity index 100% rename from server/controller/TercerSemestre/monitor.js rename to server/controller/GrupoHorario.js/horariosDIa.js diff --git a/server/controller/GrupoHorario.js/monitor.js b/server/controller/GrupoHorario.js/monitor.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index f167b56..b79b657 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -7,6 +7,7 @@ const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); const asistencia = async (body) => { const idPrimerSemestre = validar.validarId(body.idPrimerSemestre); + const hoy = moment(); return PrimerSemestre.findOne({ where: { idPrimerSemestre }, @@ -16,9 +17,8 @@ const asistencia = async (body) => { 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 - */ + if (hoy.dayOfYear() != moment(res.Horario.horario).dayOfYear()) + throw new Error('Este alumno no tiene una cita para el día de hoy.'); return PrimerSemestre.update( { asistio: true }, { where: { idPrimerSemestre } } diff --git a/server/controller/TercerSemestre/csv.js b/server/controller/TercerSemestre/csv.js index 9aac3ae..e7591d5 100644 --- a/server/controller/TercerSemestre/csv.js +++ b/server/controller/TercerSemestre/csv.js @@ -10,7 +10,7 @@ const GrupoHorario = require(`${dbPath}/GrupoHorario`); const Horario = require(`${dbPath}/Horario`); const TercerSemestre = require(`${dbPath}/TercerSemestre`); -const get = async (body) => { +const csv = async (body) => { const path = `server/uploads/tercer_semestre.csv`; const data = []; @@ -56,4 +56,4 @@ const get = async (body) => { .then((res) => path); }; -module.exports = get; +module.exports = csv; diff --git a/server/controller/TercerSemestre/registrar.js b/server/controller/TercerSemestre/registrar.js index 9835a28..5ca4241 100644 --- a/server/controller/TercerSemestre/registrar.js +++ b/server/controller/TercerSemestre/registrar.js @@ -9,7 +9,7 @@ const GrupoHorario = require(`${dbPath}/GrupoHorario`); const Horario = require(`${dbPath}/Horario`); const TercerSemestre = require(`${dbPath}/TercerSemestre`); -const get = async (body) => { +const registrar = async (body) => { const idTercerSemestre = validarId(body.idTercerSemestre); let alumno = {}; let mail = {}; @@ -54,4 +54,4 @@ const get = async (body) => { })); }; -module.exports = get; +module.exports = registrar; diff --git a/server/routes/PrimerSemestre.js b/server/routes/PrimerSemestre.js index 5255eed..5d12149 100644 --- a/server/routes/PrimerSemestre.js +++ b/server/routes/PrimerSemestre.js @@ -40,7 +40,7 @@ app.put(`${route}/asistencia`, (req, res) => { }); // GET -app.put(`${route}/asistentes`, (req, res) => { +app.get(`${route}/asistentes`, (req, res) => { return asistentes(req.query) .then((data) => { res.status(200).json(data); From 78966dfed84890a6f6451a90f77537f481979f54 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 10:59:25 -0500 Subject: [PATCH 4/9] =?UTF-8?q?correciones=20peque=C3=B1as?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controller/PrimerSemestre/asistencia.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index b79b657..ec3c1c2 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -1,16 +1,16 @@ const moment = require('moment'); const helperPath = '../../helper'; -const validar = require(`${helperPath}/validar`); +const { validarNumeroCuenta } = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); +const hoy = moment().add(12, 'd'); const asistencia = async (body) => { - const idPrimerSemestre = validar.validarId(body.idPrimerSemestre); - const hoy = moment(); + const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); return PrimerSemestre.findOne({ - where: { idPrimerSemestre }, + where: { numeroCuenta }, include: [{ model: Horario }], }) .then((res) => { @@ -21,7 +21,7 @@ const asistencia = async (body) => { throw new Error('Este alumno no tiene una cita para el día de hoy.'); return PrimerSemestre.update( { asistio: true }, - { where: { idPrimerSemestre } } + { where: { numeroCuenta } } ); }) .then((res) => ({ From 4794c32651fc8b16115d3e77a5e7364d17a597e2 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 21 Jul 2021 13:39:02 -0500 Subject: [PATCH 5/9] horarios lunes --- server/controller/CarreraHorario/horariosDia.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controller/CarreraHorario/horariosDia.js b/server/controller/CarreraHorario/horariosDia.js index a554e1b..73b09f3 100644 --- a/server/controller/CarreraHorario/horariosDia.js +++ b/server/controller/CarreraHorario/horariosDia.js @@ -2,7 +2,7 @@ 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 hoy = moment().add(12, 'd'); const horariosDia = async (body) => { return CarreraHorario.findAll({ From 22d8921093e84e43050f46335f3a9c11a166c3e9 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Thu, 22 Jul 2021 12:17:58 -0500 Subject: [PATCH 6/9] listo lector para pruebas --- server/controller/CarreraHorario/horariosDia.js | 5 ++--- server/controller/PrimerSemestre/asistencia.js | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/server/controller/CarreraHorario/horariosDia.js b/server/controller/CarreraHorario/horariosDia.js index 73b09f3..f6108d9 100644 --- a/server/controller/CarreraHorario/horariosDia.js +++ b/server/controller/CarreraHorario/horariosDia.js @@ -2,7 +2,7 @@ const moment = require('moment'); const dbPath = '../../db/tablas'; const CarreraHorario = require(`${dbPath}/CarreraHorario`); const Horario = require(`${dbPath}/Horario`); -const hoy = moment().add(12, 'd'); +const hoy = moment().add(11, 'd'); const horariosDia = async (body) => { return CarreraHorario.findAll({ @@ -14,9 +14,8 @@ const horariosDia = async (body) => { for (let i = 0; i < res.length; i++) { const fecha = moment(res[i].Horario.horario); - if (hoy.dayOfYear() === fecha.dayOfYear()) { + if (hoy.dayOfYear() === fecha.dayOfYear()) data.push({ Horario: res[i].Horario }); - } } return data; }); diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index ec3c1c2..51b1e1d 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -4,7 +4,7 @@ const { validarNumeroCuenta } = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const hoy = moment().add(12, 'd'); +const hoy = moment().add(11, 'd'); const asistencia = async (body) => { const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); @@ -15,10 +15,10 @@ const asistencia = async (body) => { }) .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.'); if (hoy.dayOfYear() != moment(res.Horario.horario).dayOfYear()) throw new Error('Este alumno no tiene una cita para el día de hoy.'); + if (res.asistio) + throw new Error('Ya fue registrada la asistencia de este alumno.'); return PrimerSemestre.update( { asistio: true }, { where: { numeroCuenta } } From 407f29273803209db82f05c99b20ed96372bf1fa Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Fri, 23 Jul 2021 13:02:58 -0500 Subject: [PATCH 7/9] gurpo horario --- server/controller/CarreraHorario/get.js | 5 +-- .../controller/CarreraHorario/horariosDia.js | 13 +++---- server/controller/CarreraHorario/monitor.js | 4 +- .../controller/GrupoHorario.js/horariosDIa.js | 0 server/controller/GrupoHorario.js/monitor.js | 0 server/controller/GrupoHorario/horariosDia.js | 21 ++++++++++ server/controller/GrupoHorario/monitor.js | 29 ++++++++++++++ .../controller/PrimerSemestre/asistencia.js | 2 +- .../controller/PrimerSemestre/asistentes.js | 10 +++-- server/controller/PrimerSemestre/csv.js | 6 ++- .../controller/TercerSemestre/asistencia.js | 38 +++++++++++++++++++ .../controller/TercerSemestre/asistentes.js | 19 ++++++++++ server/controller/TercerSemestre/csv.js | 6 ++- server/controller/TercerSemestre/registrar.js | 2 +- server/routes/GrupoHorario.js | 29 ++++++++++++++ server/routes/index.js | 1 + 16 files changed, 163 insertions(+), 22 deletions(-) delete mode 100644 server/controller/GrupoHorario.js/horariosDIa.js delete mode 100644 server/controller/GrupoHorario.js/monitor.js create mode 100644 server/controller/GrupoHorario/horariosDia.js create mode 100644 server/controller/GrupoHorario/monitor.js create mode 100644 server/routes/GrupoHorario.js diff --git a/server/controller/CarreraHorario/get.js b/server/controller/CarreraHorario/get.js index 5b2894c..a78e064 100644 --- a/server/controller/CarreraHorario/get.js +++ b/server/controller/CarreraHorario/get.js @@ -7,6 +7,7 @@ const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); const get = async (body) => { const idCarrera = validarId(body.idCarrera); + const data = []; return Carrera.findOne({ where: { idCarrera } }) .then((res) => { @@ -17,10 +18,8 @@ const get = async (body) => { }); }) .then(async (res) => { - const data = []; - for (let i = 0; i < res.length; i++) { - let lugaresOcupados = await PrimerSemestre.findAll({ + const lugaresOcupados = await PrimerSemestre.findAll({ where: { idHorario: res[i].Horario.idHorario }, }).then((res) => res.length); diff --git a/server/controller/CarreraHorario/horariosDia.js b/server/controller/CarreraHorario/horariosDia.js index f6108d9..276ea07 100644 --- a/server/controller/CarreraHorario/horariosDia.js +++ b/server/controller/CarreraHorario/horariosDia.js @@ -2,21 +2,18 @@ const moment = require('moment'); const dbPath = '../../db/tablas'; const CarreraHorario = require(`${dbPath}/CarreraHorario`); const Horario = require(`${dbPath}/Horario`); -const hoy = moment().add(11, 'd'); +const hoy = moment().add(10, 'd'); const horariosDia = async (body) => { + const data = []; + 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()) + for (let i = 0; i < res.length; i++) + if (hoy.dayOfYear() === moment(res[i].Horario.horario).dayOfYear()) data.push({ Horario: res[i].Horario }); - } return data; }); }; diff --git a/server/controller/CarreraHorario/monitor.js b/server/controller/CarreraHorario/monitor.js index 87a33dc..8a2b8fd 100644 --- a/server/controller/CarreraHorario/monitor.js +++ b/server/controller/CarreraHorario/monitor.js @@ -5,12 +5,12 @@ const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); const monitor = async (body) => { + const data = []; + return CarreraHorario.findAll({ include: [{ model: Horario }, { model: Carrera }], order: ['idHorario'], }).then(async (res) => { - const data = []; - for (let i = 0; i < res.length; i++) { const asistentes = await PrimerSemestre.findAll({ where: { idHorario: res[i].idHorario }, diff --git a/server/controller/GrupoHorario.js/horariosDIa.js b/server/controller/GrupoHorario.js/horariosDIa.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/controller/GrupoHorario.js/monitor.js b/server/controller/GrupoHorario.js/monitor.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/controller/GrupoHorario/horariosDia.js b/server/controller/GrupoHorario/horariosDia.js new file mode 100644 index 0000000..ab48d51 --- /dev/null +++ b/server/controller/GrupoHorario/horariosDia.js @@ -0,0 +1,21 @@ +const moment = require('moment'); +const dbPath = '../../db/tablas'; +const GrupoHorario = require(`${dbPath}/GrupoHorario`); +const Horario = require(`${dbPath}/Horario`); +const hoy = moment().add(17, 'd'); + +const horariosDia = async (body) => { + const data = []; + + return GrupoHorario.findAll({ + include: [{ model: Horario }], + order: ['idHorario'], + }).then(async (res) => { + for (let i = 0; i < res.length; i++) + if (hoy.dayOfYear() === moment(res[i].Horario.horario).dayOfYear()) + data.push({ Horario: res[i].Horario }); + return data; + }); +}; + +module.exports = horariosDia; diff --git a/server/controller/GrupoHorario/monitor.js b/server/controller/GrupoHorario/monitor.js new file mode 100644 index 0000000..be23a16 --- /dev/null +++ b/server/controller/GrupoHorario/monitor.js @@ -0,0 +1,29 @@ +const dbPath = '../../db/tablas'; +const Carrera = require(`${dbPath}/Carrera`); +const Grupo = require(`${dbPath}/Grupo`); +const GrupoHorario = require(`${dbPath}/GrupoHorario`); +const Horario = require(`${dbPath}/Horario`); +const TercerSemestre = require(`${dbPath}/TercerSemestre`); + +const monitor = async (body) => { + const data = []; + + return GrupoHorario.findAll({ + include: [ + { model: Horario }, + { model: Grupo, include: [{ model: Carrera }] }, + ], + order: ['idHorario'], + }).then(async (res) => { + for (let i = 0; i < res.length; i++) { + const asistentes = await TercerSemestre.findAll({ + where: { idGrupo: res[i].idGrupo, deseaAsistir: true }, + }).then((res) => res.length); + + data.push({ GrupoHorario: res[i], asistentes }); + } + return data; + }); +}; + +module.exports = monitor; diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index 51b1e1d..c10c9a4 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -4,7 +4,7 @@ const { validarNumeroCuenta } = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const hoy = moment().add(11, 'd'); +const hoy = moment().add(10, 'd'); const asistencia = async (body) => { const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); diff --git a/server/controller/PrimerSemestre/asistentes.js b/server/controller/PrimerSemestre/asistentes.js index 9248a3a..c951001 100644 --- a/server/controller/PrimerSemestre/asistentes.js +++ b/server/controller/PrimerSemestre/asistentes.js @@ -3,14 +3,18 @@ const validar = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); const Grupo = require(`${dbPath}/Grupo`); +const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); const asistentes = async (body) => { const idHorario = validar.validarId(body.idHorario); - return PrimerSemestre.findAll({ - where: { idHorario }, - include: [{ model: Grupo, include: [{ model: Carrera }] }], + return Horario.findOne({ where: { idHorario } }).then((res) => { + if (!res) throw new Error('No existe este horario.'); + return PrimerSemestre.findAll({ + where: { idHorario }, + include: [{ model: Grupo, include: [{ model: Carrera }] }], + }); }); }; diff --git a/server/controller/PrimerSemestre/csv.js b/server/controller/PrimerSemestre/csv.js index 322392a..2ddf5b1 100644 --- a/server/controller/PrimerSemestre/csv.js +++ b/server/controller/PrimerSemestre/csv.js @@ -34,18 +34,20 @@ const csv = async (body) => { nombre: res[i].nombre, carrera: res[i].Grupo.Carrera.carrera, grupo: res[i].Grupo.grupo, - horario: `${ + dia: `${ horario.date() < 10 ? '0' + horario.date() : horario.date() }/${ horario.month() + 1 < 10 ? '0' + (horario.month() + 1) : horario.month() + 1 - }/${horario.year()} ${ + }/${horario.year()}`, + hora: `${ horario.hour() < 10 ? '0' + horario.hour() : horario.hour() }:${ horario.minute() < 10 ? '0' + horario.minute() : horario.minute() }`, correo: res[i].correo, + asistio: res[i].asistio ? 'si' : 'no', }); } await helper.eliminarArchivo(path).catch((err) => {}); diff --git a/server/controller/TercerSemestre/asistencia.js b/server/controller/TercerSemestre/asistencia.js index e69de29..78195a4 100644 --- a/server/controller/TercerSemestre/asistencia.js +++ b/server/controller/TercerSemestre/asistencia.js @@ -0,0 +1,38 @@ +const moment = require('moment'); +const helperPath = '../../helper'; +const { validarNumeroCuenta } = require(`${helperPath}/validar`); +const dbPath = '../../db/tablas'; +const GrupoHorario = require(`${dbPath}/GrupoHorario`); +const Horario = require(`${dbPath}/Horario`); +const TercerSemestre = require(`${dbPath}/TercerSemestre`); +const hoy = moment().add(17, 'd'); + +const asistencia = async (body) => { + const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); + + return TercerSemestre.findOne({ + where: { numeroCuenta }, + }) + .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.'); + return GrupoHorario.findOne({ + where: { idGrupo: res.idGrupo }, + include: [{ model: Horario }], + }); + }) + .then((res) => { + if (hoy.dayOfYear() != moment(res.Horario.horario).dayOfYear()) + throw new Error('Este alumno no tiene una cita para el día de hoy.'); + return TercerSemestre.update( + { asistio: true }, + { where: { numeroCuenta } } + ); + }) + .then((res) => ({ + message: 'Se registro correctamente la asistencia de este alumno.', + })); +}; + +module.exports = asistencia; diff --git a/server/controller/TercerSemestre/asistentes.js b/server/controller/TercerSemestre/asistentes.js index e69de29..1fe6993 100644 --- a/server/controller/TercerSemestre/asistentes.js +++ b/server/controller/TercerSemestre/asistentes.js @@ -0,0 +1,19 @@ +const helperPath = '../../helper'; +const validar = require(`${helperPath}/validar`); +const dbPath = '../../db/tablas'; +const Carrera = require(`${dbPath}/Carrera`); +const Grupo = require(`${dbPath}/Grupo`); +const TercerSemestre = require(`${dbPath}/TercerSemestre`); + +const asistentes = async (body) => { + const idGrupo = validar.validarId(body.idGrupo); + + return Grupo.findOne({ where: { idGrupo } }).then((res) => { + return TercerSemestre.findAll({ + where: { idGrupo }, + include: [{ model: Grupo, include: [{ model: Carrera }] }], + }); + }); +}; + +module.exports = asistentes; diff --git a/server/controller/TercerSemestre/csv.js b/server/controller/TercerSemestre/csv.js index e7591d5..f851bac 100644 --- a/server/controller/TercerSemestre/csv.js +++ b/server/controller/TercerSemestre/csv.js @@ -37,17 +37,19 @@ const csv = async (body) => { nombre: res[i].nombre, carrera: res[i].Grupo.Carrera.carrera, grupo: res[i].Grupo.grupo, - horario: `${ + dia: `${ horario.date() < 10 ? '0' + horario.date() : horario.date() }/${ horario.month() + 1 < 10 ? '0' + (horario.month() + 1) : horario.month() + 1 - }/${horario.year()} ${ + }/${horario.year()}`, + hora: `${ horario.hour() < 10 ? '0' + horario.hour() : horario.hour() }:${ horario.minute() < 10 ? '0' + horario.minute() : horario.minute() }`, + asistio: res[i].asistio ? 'si' : 'no', }); } await helper.eliminarArchivo(path).catch((err) => {}); diff --git a/server/controller/TercerSemestre/registrar.js b/server/controller/TercerSemestre/registrar.js index 5ca4241..2a7ea96 100644 --- a/server/controller/TercerSemestre/registrar.js +++ b/server/controller/TercerSemestre/registrar.js @@ -50,7 +50,7 @@ const registrar = async (body) => { ) .then((res) => ({ message: - 'Te has registrado correctamente, hemos mandado tu comprobante a tu correo.', + 'Te has registrado correctamente, hemos mandado tu comprobante a tu correo pcpuma.', })); }; diff --git a/server/routes/GrupoHorario.js b/server/routes/GrupoHorario.js new file mode 100644 index 0000000..a78936b --- /dev/null +++ b/server/routes/GrupoHorario.js @@ -0,0 +1,29 @@ +const express = require('express'); +const app = express(); +const route = '/grupo_horario'; +const controllerPath = '../controller/GrupoHorario'; +const horariosDia = require(`${controllerPath}/horariosDia`); +const monitor = require(`${controllerPath}/monitor`); + +// GET +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) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + +module.exports = app; diff --git a/server/routes/index.js b/server/routes/index.js index 59ec4b6..56cf8da 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -4,6 +4,7 @@ const app = express(); app.use(require('./Carrera')); app.use(require('./CarreraHorario')); app.use(require('./Grupo')); +app.use(require('./GrupoHorario')); app.use(require('./PrimerSemestre')); app.use(require('./TercerSemestre')); From 67fcbdefb59867e48f651dd28d84c75f4c46ae6e Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Fri, 23 Jul 2021 14:05:26 -0500 Subject: [PATCH 8/9] routes tercer semestre --- .../controller/TercerSemestre/asistentes.js | 23 ++++++++++++++----- server/routes/TercerSemestre.js | 22 ++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/server/controller/TercerSemestre/asistentes.js b/server/controller/TercerSemestre/asistentes.js index 1fe6993..8e87eeb 100644 --- a/server/controller/TercerSemestre/asistentes.js +++ b/server/controller/TercerSemestre/asistentes.js @@ -3,17 +3,28 @@ const validar = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Carrera = require(`${dbPath}/Carrera`); const Grupo = require(`${dbPath}/Grupo`); +const GrupoHorario = require(`${dbPath}/GrupoHorario`); +const Horario = require(`${dbPath}/Horario`); const TercerSemestre = require(`${dbPath}/TercerSemestre`); const asistentes = async (body) => { - const idGrupo = validar.validarId(body.idGrupo); + const idHorario = validar.validarId(body.idHorario); - return Grupo.findOne({ where: { idGrupo } }).then((res) => { - return TercerSemestre.findAll({ - where: { idGrupo }, - include: [{ model: Grupo, include: [{ model: Carrera }] }], + return Horario.findOne({ where: { idHorario } }) + .then((res) => { + if (!res) throw new Error('No existe este horario.'); + return GrupoHorario.findOne({ + where: { idHorario }, + }); + }) + .then((res) => { + if (!res) + throw new Error('No hay un grupo que tenga asignado este horario.'); + return TercerSemestre.findAll({ + where: { idGrupo: res.idGrupo, deseaAsistir: true }, + include: [{ model: Grupo, include: [{ model: Carrera }] }], + }); }); - }); }; module.exports = asistentes; diff --git a/server/routes/TercerSemestre.js b/server/routes/TercerSemestre.js index afb68e4..4f9f640 100644 --- a/server/routes/TercerSemestre.js +++ b/server/routes/TercerSemestre.js @@ -2,6 +2,8 @@ const express = require('express'); const app = express(); const route = '/tercer_semestre'; const controllerPath = '../controller/TercerSemestre'; +const asistencia = require(`${controllerPath}/asistencia`); +const asistentes = require(`${controllerPath}/asistentes`); const csv = require(`${controllerPath}/csv`); const get = require(`${controllerPath}/get`); const registrar = require(`${controllerPath}/registrar`); @@ -28,6 +30,16 @@ app.put(`${route}/registrar`, (req, res) => { }); }); +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.get(`${route}`, (req, res) => { return get(req.query) @@ -39,4 +51,14 @@ app.get(`${route}`, (req, res) => { }); }); +app.get(`${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; From d4153e1b901609a9e4add394914c1349ea9a89f3 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Mon, 26 Jul 2021 18:25:40 -0500 Subject: [PATCH 9/9] 45 max --- server/controller/CarreraHorario/get.js | 4 ++-- server/controller/CarreraHorario/horariosDia.js | 2 +- server/controller/GrupoHorario/horariosDia.js | 2 +- server/controller/PrimerSemestre/asistencia.js | 2 +- server/controller/PrimerSemestre/registrar.js | 2 +- server/controller/TercerSemestre/asistencia.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/controller/CarreraHorario/get.js b/server/controller/CarreraHorario/get.js index a78e064..894d83e 100644 --- a/server/controller/CarreraHorario/get.js +++ b/server/controller/CarreraHorario/get.js @@ -23,11 +23,11 @@ const get = async (body) => { where: { idHorario: res[i].Horario.idHorario }, }).then((res) => res.length); - if (lugaresOcupados < 50) + if (lugaresOcupados < 45) data.push({ idHorario: res[i].Horario.idHorario, horario: res[i].Horario.horario, - lugares: 50 - lugaresOcupados, + lugares: 45 - lugaresOcupados, }); } return data; diff --git a/server/controller/CarreraHorario/horariosDia.js b/server/controller/CarreraHorario/horariosDia.js index 276ea07..68cfc3c 100644 --- a/server/controller/CarreraHorario/horariosDia.js +++ b/server/controller/CarreraHorario/horariosDia.js @@ -2,7 +2,7 @@ const moment = require('moment'); const dbPath = '../../db/tablas'; const CarreraHorario = require(`${dbPath}/CarreraHorario`); const Horario = require(`${dbPath}/Horario`); -const hoy = moment().add(10, 'd'); +const hoy = moment().add(7, 'd'); const horariosDia = async (body) => { const data = []; diff --git a/server/controller/GrupoHorario/horariosDia.js b/server/controller/GrupoHorario/horariosDia.js index ab48d51..0031cfe 100644 --- a/server/controller/GrupoHorario/horariosDia.js +++ b/server/controller/GrupoHorario/horariosDia.js @@ -2,7 +2,7 @@ const moment = require('moment'); const dbPath = '../../db/tablas'; const GrupoHorario = require(`${dbPath}/GrupoHorario`); const Horario = require(`${dbPath}/Horario`); -const hoy = moment().add(17, 'd'); +const hoy = moment().add(14, 'd'); const horariosDia = async (body) => { const data = []; diff --git a/server/controller/PrimerSemestre/asistencia.js b/server/controller/PrimerSemestre/asistencia.js index c10c9a4..3815344 100644 --- a/server/controller/PrimerSemestre/asistencia.js +++ b/server/controller/PrimerSemestre/asistencia.js @@ -4,7 +4,7 @@ const { validarNumeroCuenta } = require(`${helperPath}/validar`); const dbPath = '../../db/tablas'; const Horario = require(`${dbPath}/Horario`); const PrimerSemestre = require(`${dbPath}/PrimerSemestre`); -const hoy = moment().add(10, 'd'); +const hoy = moment().add(7, 'd'); const asistencia = async (body) => { const numeroCuenta = validarNumeroCuenta(body.numeroCuenta); diff --git a/server/controller/PrimerSemestre/registrar.js b/server/controller/PrimerSemestre/registrar.js index e0c7b5c..c8d40df 100644 --- a/server/controller/PrimerSemestre/registrar.js +++ b/server/controller/PrimerSemestre/registrar.js @@ -57,7 +57,7 @@ const registrar = async (body) => { }); }) .then((res) => { - if (res.length >= 50) + if (res.length >= 45) throw new Error('Este horario ya esta lleno, elige otro.'); return PrimerSemestre.create({ numeroCuenta, diff --git a/server/controller/TercerSemestre/asistencia.js b/server/controller/TercerSemestre/asistencia.js index 78195a4..777bfbb 100644 --- a/server/controller/TercerSemestre/asistencia.js +++ b/server/controller/TercerSemestre/asistencia.js @@ -5,7 +5,7 @@ const dbPath = '../../db/tablas'; const GrupoHorario = require(`${dbPath}/GrupoHorario`); const Horario = require(`${dbPath}/Horario`); const TercerSemestre = require(`${dbPath}/TercerSemestre`); -const hoy = moment().add(17, 'd'); +const hoy = moment().add(14, 'd'); const asistencia = async (body) => { const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);