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;