pasar lsita listo

This commit is contained in:
2021-10-24 14:41:03 -05:00
parent 12668d894c
commit 4822b68407
2 changed files with 19 additions and 2 deletions
+7 -2
View File
@@ -1,7 +1,7 @@
const moment = require('moment');
const dbHelper = '../../helper';
const gmail = require(`${dbHelper}/gmail`);
const { correoAsistencia } = require(`${dbHelper}/correoAlumno`);
const { correoAsistencia } = require(`${dbHelper}/correos`);
const { validarId } = require(`${dbHelper}/validar`);
const dbPath = '../../db/tablas';
const Alumno = require(`${dbPath}/Alumno`);
@@ -10,7 +10,8 @@ const ahora = moment();
const pasarLista = async (body) => {
const idAlumno = validarId(body.idAlumno);
const correo = {};
let correo = {};
let horario = moment();
return Alumno.findOne({
where: { idAlumno },
@@ -18,7 +19,11 @@ const pasarLista = async (body) => {
})
.then((res) => {
if (!res) throw new Error('No existe este alumno.');
horario = moment(res.Horario.horario);
if (res.asistio) throw new Error('Ya paso lista a este alumno.');
if (ahora < horario) throw new Error('Aun no es la hora del recorrido.');
horario.add(20, 'm');
if (ahora > horario) throw new Error('Ya paso la hora del recorrido.');
return Alumno.update({ asistio: true }, { where: { idAlumno } });
})
.then((res) => {
+12
View File
@@ -5,6 +5,7 @@ const controllerPath = '../controller/Alumno';
const get = require(`${controllerPath}/get`);
const monitor = require(`${controllerPath}/monitor`);
const registrar = require(`${controllerPath}/registrar`);
const pasarLista = require(`${controllerPath}/pasarLista`);
// POST
app.post(`${route}/registrar`, (req, res) => {
@@ -17,6 +18,17 @@ app.post(`${route}/registrar`, (req, res) => {
});
});
// PUT
app.put(`${route}/pasar_lista`, (req, res) => {
return pasarLista(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)