This commit is contained in:
Lemuel Marquez
2021-07-26 18:34:29 -05:00
18 changed files with 306 additions and 32 deletions
+4 -6
View File
@@ -1,4 +1,3 @@
const moment = require('moment');
const { validarId } = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
@@ -8,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) => {
@@ -18,18 +18,16 @@ 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);
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;
@@ -0,0 +1,21 @@
const moment = require('moment');
const dbPath = '../../db/tablas';
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
const Horario = require(`${dbPath}/Horario`);
const hoy = moment().add(7, 'd');
const horariosDia = async (body) => {
const data = [];
return CarreraHorario.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;
@@ -1,22 +1,16 @@
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) => {
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 },
@@ -28,4 +22,4 @@ const get = async (body) => {
});
};
module.exports = get;
module.exports = monitor;
@@ -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(14, '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;
+29
View File
@@ -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;
@@ -0,0 +1,32 @@
const moment = require('moment');
const helperPath = '../../helper';
const { validarNumeroCuenta } = require(`${helperPath}/validar`);
const dbPath = '../../db/tablas';
const Horario = require(`${dbPath}/Horario`);
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
const hoy = moment().add(7, 'd');
const asistencia = async (body) => {
const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
return PrimerSemestre.findOne({
where: { numeroCuenta },
include: [{ model: Horario }],
})
.then((res) => {
if (!res) throw new Error('No existe 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 } }
);
})
.then((res) => ({
message: 'Se registro correctamente la asistencia de este alumno.',
}));
};
module.exports = asistencia;
@@ -0,0 +1,21 @@
const helperPath = '../../helper';
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 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 }] }],
});
});
};
module.exports = asistentes;
+4 -3
View File
@@ -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 = [];
@@ -47,6 +47,7 @@ const get = async (body) => {
horario.minute() < 10 ? '0' + horario.minute() : horario.minute()
}`,
correo: res[i].correo,
asistio: res[i].asistio ? 'si' : 'no',
});
}
await helper.eliminarArchivo(path).catch((err) => {});
@@ -55,4 +56,4 @@ const get = async (body) => {
.then((res) => path);
};
module.exports = get;
module.exports = csv;
@@ -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);
@@ -57,7 +57,7 @@ const get = 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,
@@ -82,4 +82,4 @@ const get = async (body) => {
}));
};
module.exports = get;
module.exports = registrar;
@@ -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(14, '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;
@@ -0,0 +1,30 @@
const helperPath = '../../helper';
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 idHorario = validar.validarId(body.idHorario);
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;
+6 -4
View File
@@ -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 = [];
@@ -37,17 +37,19 @@ const get = 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) => {});
@@ -56,4 +58,4 @@ const get = async (body) => {
.then((res) => path);
};
module.exports = get;
module.exports = csv;
@@ -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 = {};
@@ -50,8 +50,8 @@ const get = 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.',
}));
};
module.exports = get;
module.exports = registrar;
+23
View File
@@ -3,7 +3,10 @@ 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
app.get(`${route}`, (req, res) => {
return get(req.query)
.then((data) => {
@@ -14,4 +17,24 @@ 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) => {
res.status(200).json(data);
})
.catch((err) => {
res.status(400).json({ message: err.message });
});
});
module.exports = app;
+29
View File
@@ -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;
+15 -3
View File
@@ -3,7 +3,8 @@ const app = express();
const route = '/primer_semestre';
const controllerPath = '../controller/PrimerSemestre';
const csv = require(`${controllerPath}/csv`);
const graficas = require(`${controllerPath}/graficas`);
const asistencia = require(`${controllerPath}/asistencia`);
const asistentes = require(`${controllerPath}/asistentes`);
const registrar = require(`${controllerPath}/registrar`);
// POST
@@ -27,9 +28,20 @@ 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.get(`${route}/graficas`, (req, res) => {
return graficas(req.body)
app.get(`${route}/asistentes`, (req, res) => {
return asistentes(req.query)
.then((data) => {
res.status(200).json(data);
})
+22
View File
@@ -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;
+1
View File
@@ -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'));