nueva db
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
// const Carrera = require(`${dbPath}/Carrera`);
|
||||
// const Grupo = require(`${dbPath}/Grupo`);
|
||||
// const Horario = require(`${dbPath}/Horario`);
|
||||
// const GrupoHorario = require(`${dbPath}/GrupoHorario`);
|
||||
// const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
// const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
|
||||
// let alumnoTercerSemestre = {};
|
||||
// return TercerSemestre.findOne({
|
||||
// where: { numeroCuenta },
|
||||
// include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
// })
|
||||
// .then((res) => {
|
||||
// if (!res) throw new Error('No existe esta alumno.');
|
||||
// if (res.deseaAsistir)
|
||||
// throw new Error('Ya se registro a este alumno al recorrido.');
|
||||
// alumnoTercerSemestre = res;
|
||||
// delete alumnoTercerSemestre.dataValues.idGrupo;
|
||||
// delete alumnoTercerSemestre.dataValues.Grupo.dataValues.idCarrera;
|
||||
// return GrupoHorario.findOne({
|
||||
// where: { idGrupo: alumnoTercerSemestre.Grupo.idGrupo },
|
||||
// include: [{ model: Horario }],
|
||||
// });
|
||||
// })
|
||||
// .then((res) => {
|
||||
// delete res.dataValues.idHorario;
|
||||
// delete res.dataValues.idGrupo;
|
||||
// return { alumnoTercerSemestre, GrupoHorario: res };
|
||||
// });
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,5 +0,0 @@
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
|
||||
const get = async () => Carrera.findAll();
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,37 +0,0 @@
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
const idCarrera = validarId(body.idCarrera);
|
||||
const data = [];
|
||||
|
||||
return Carrera.findOne({ where: { idCarrera } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta carrera.');
|
||||
return CarreraHorario.findAll({
|
||||
where: { idCarrera },
|
||||
include: [{ model: Horario }],
|
||||
});
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const lugaresOcupados = await PrimerSemestre.findAll({
|
||||
where: { idHorario: res[i].Horario.idHorario },
|
||||
}).then((res) => res.length);
|
||||
|
||||
if (lugaresOcupados < 45)
|
||||
data.push({
|
||||
idHorario: res[i].Horario.idHorario,
|
||||
horario: res[i].Horario.horario,
|
||||
lugares: 45 - lugaresOcupados,
|
||||
});
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,21 +0,0 @@
|
||||
const moment = require('moment');
|
||||
const dbPath = '../../db/tablas';
|
||||
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const hoy = moment();
|
||||
|
||||
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,25 +0,0 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
||||
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) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const asistentes = await PrimerSemestre.findAll({
|
||||
where: { idHorario: res[i].idHorario },
|
||||
}).then((res) => res.length);
|
||||
|
||||
data.push({ CarreraHorario: res[i], asistentes });
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = monitor;
|
||||
@@ -1,23 +0,0 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
|
||||
const get = async (body) => {
|
||||
const idCarrera = validarId(body.idCarrera);
|
||||
|
||||
return Carrera.findOne({ where: { idCarrera } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta carrera.');
|
||||
return Grupo.findAll({
|
||||
where: { idCarrera, grupo: { [Op.like]: '11%' } },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
for (let i = 0; i < res.length; i++) delete res[i].dataValues.idCarrera;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,21 +0,0 @@
|
||||
const moment = require('moment');
|
||||
const dbPath = '../../db/tablas';
|
||||
const GrupoHorario = require(`${dbPath}/GrupoHorario`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const hoy = moment();
|
||||
|
||||
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;
|
||||
@@ -1,29 +0,0 @@
|
||||
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,35 @@
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
// const Carrera = require(`${dbPath}/Carrera`);
|
||||
// const Grupo = require(`${dbPath}/Grupo`);
|
||||
// const Horario = require(`${dbPath}/Horario`);
|
||||
// const GrupoHorario = require(`${dbPath}/GrupoHorario`);
|
||||
// const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
// const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
|
||||
// let alumnoTercerSemestre = {};
|
||||
// return TercerSemestre.findOne({
|
||||
// where: { numeroCuenta },
|
||||
// include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
// })
|
||||
// .then((res) => {
|
||||
// if (!res) throw new Error('No existe esta alumno.');
|
||||
// if (res.deseaAsistir)
|
||||
// throw new Error('Ya se registro a este alumno al recorrido.');
|
||||
// alumnoTercerSemestre = res;
|
||||
// delete alumnoTercerSemestre.dataValues.idGrupo;
|
||||
// delete alumnoTercerSemestre.dataValues.Grupo.dataValues.idCarrera;
|
||||
// return GrupoHorario.findOne({
|
||||
// where: { idGrupo: alumnoTercerSemestre.Grupo.idGrupo },
|
||||
// include: [{ model: Horario }],
|
||||
// });
|
||||
// })
|
||||
// .then((res) => {
|
||||
// delete res.dataValues.idHorario;
|
||||
// delete res.dataValues.idGrupo;
|
||||
// return { alumnoTercerSemestre, GrupoHorario: res };
|
||||
// });
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,26 +0,0 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
|
||||
|
||||
const alumnosCarrera = async (body) => {
|
||||
const data = [];
|
||||
|
||||
return Carrera.findAll().then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const alumnos = await PrimerSemestre.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Grupo,
|
||||
where: { idCarrera: res[i].idCarrera },
|
||||
},
|
||||
],
|
||||
}).then((res) => res.length);
|
||||
|
||||
data.push({ Carrera: res[i], alumnos });
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = alumnosCarrera;
|
||||
@@ -1,32 +0,0 @@
|
||||
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();
|
||||
|
||||
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;
|
||||
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
@@ -1,59 +0,0 @@
|
||||
const moment = require('moment');
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const encriptar = require(`${helperPath}/encriptar`);
|
||||
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 csv = async (body) => {
|
||||
const path = `server/uploads/primer_semestre.csv`;
|
||||
const data = [];
|
||||
|
||||
if (
|
||||
!encriptar.comparar(
|
||||
body.password,
|
||||
'$2b$10$8FDx15tey9s9ITXNNE/Qourk1EfyrC6W8/ROqI0sGMuyOAuZ8oHMO'
|
||||
)
|
||||
)
|
||||
throw new Error('Contraseña incorrecta.');
|
||||
return PrimerSemestre.findAll({
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const horario = await Horario.findOne({
|
||||
where: { idHorario: res[i].idHorario },
|
||||
}).then((res) => moment(res.horario));
|
||||
|
||||
data.push({
|
||||
numeroCuenta: res[i].numeroCuenta,
|
||||
nombre: res[i].nombre,
|
||||
carrera: res[i].Grupo.Carrera.carrera,
|
||||
grupo: res[i].Grupo.grupo,
|
||||
dia: `${
|
||||
horario.date() < 10 ? '0' + horario.date() : horario.date()
|
||||
}/${
|
||||
horario.month() + 1 < 10
|
||||
? '0' + (horario.month() + 1)
|
||||
: horario.month() + 1
|
||||
}/${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) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then((res) => path);
|
||||
};
|
||||
|
||||
module.exports = csv;
|
||||
@@ -1,85 +0,0 @@
|
||||
const helperPath = '../../helper';
|
||||
const gmail = require(`${helperPath}/gmail`);
|
||||
const correos = require(`${helperPath}/correos`);
|
||||
const validar = require(`${helperPath}/validar`);
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const CarreraHorario = require(`${dbPath}/CarreraHorario`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const PrimerSemestre = require(`${dbPath}/PrimerSemestre`);
|
||||
|
||||
const registrar = async (body) => {
|
||||
const idCarrera = validar.validarId(body.idCarrera);
|
||||
const idGrupo = validar.validarId(body.idGrupo);
|
||||
const idHorario = validar.validarId(body.idHorario);
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const correo = validar.validarCorreo(body.correo);
|
||||
const nombre = validar.validarTexto(body.nombre, 'El nombre', 70);
|
||||
let mail = {};
|
||||
let horario = {};
|
||||
let carrera = {};
|
||||
|
||||
return Carrera.findOne({ where: { idCarrera } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta carrera.');
|
||||
carrera = res;
|
||||
return Grupo.findOne({
|
||||
where: { idGrupo },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este grupo.');
|
||||
return Grupo.findOne({ where: { idGrupo, idCarrera } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res)
|
||||
throw new Error('Este grupo no pertenece a la carrera indicada.');
|
||||
if (res.grupo[0] === '2' && res.grupo[1] === '2')
|
||||
throw new Error(
|
||||
'Este grupo es de segundo semestre, no es valido para este registro.'
|
||||
);
|
||||
return Horario.findOne({ where: { idHorario } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe este horario.');
|
||||
horario = res;
|
||||
return CarreraHorario.findOne({ where: { idCarrera, idHorario } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Esta carrera no tiene asignado este horario.');
|
||||
return PrimerSemestre.findOne({ where: { numeroCuenta } });
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Ya se registro a este alumno al recorrido.');
|
||||
return PrimerSemestre.findAll({
|
||||
where: { idHorario },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.length >= 45)
|
||||
throw new Error('Este horario ya esta lleno, elige otro.');
|
||||
return PrimerSemestre.create({
|
||||
numeroCuenta,
|
||||
correo,
|
||||
nombre,
|
||||
idHorario,
|
||||
idGrupo,
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
mail = correos.correoPrimerSemestre(
|
||||
res.numeroCuenta,
|
||||
res.nombre,
|
||||
carrera.carrera,
|
||||
horario.horario
|
||||
);
|
||||
return gmail(mail.subject, res.correo, mail.message);
|
||||
})
|
||||
.then((res) => ({
|
||||
message:
|
||||
'Te has registrado correctamente, hemos mandado tu comprobante a tu correo.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = registrar;
|
||||
@@ -1,27 +0,0 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
||||
|
||||
const alumnosCarrera = async (body) => {
|
||||
const data = [];
|
||||
|
||||
return Carrera.findAll().then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const alumnos = await TercerSemestre.findAll({
|
||||
where: { deseaAsistir: true },
|
||||
include: [
|
||||
{
|
||||
model: Grupo,
|
||||
where: { idCarrera: res[i].idCarrera },
|
||||
},
|
||||
],
|
||||
}).then((res) => res.length);
|
||||
|
||||
data.push({ Carrera: res[i], alumnos });
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = alumnosCarrera;
|
||||
@@ -1,38 +0,0 @@
|
||||
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();
|
||||
|
||||
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;
|
||||
@@ -1,30 +0,0 @@
|
||||
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;
|
||||
@@ -1,61 +0,0 @@
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const moment = require('moment');
|
||||
const helperPath = '../../helper';
|
||||
const helper = require(`${helperPath}/helper`);
|
||||
const encriptar = require(`${helperPath}/encriptar`);
|
||||
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 csv = async (body) => {
|
||||
const path = `server/uploads/tercer_semestre.csv`;
|
||||
const data = [];
|
||||
|
||||
if (
|
||||
!encriptar.comparar(
|
||||
body.password,
|
||||
'$2b$10$8FDx15tey9s9ITXNNE/Qourk1EfyrC6W8/ROqI0sGMuyOAuZ8oHMO'
|
||||
)
|
||||
)
|
||||
throw new Error('Contraseña incorrecta.');
|
||||
return TercerSemestre.findAll({
|
||||
where: { deseaAsistir: true },
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
const horario = await GrupoHorario.findOne({
|
||||
where: { idGrupo: res[i].idGrupo },
|
||||
include: [{ model: Horario }],
|
||||
}).then((res) => moment(res.Horario.horario));
|
||||
|
||||
data.push({
|
||||
numeroCuenta: res[i].numeroCuenta,
|
||||
nombre: res[i].nombre,
|
||||
carrera: res[i].Grupo.Carrera.carrera,
|
||||
grupo: res[i].Grupo.grupo,
|
||||
dia: `${
|
||||
horario.date() < 10 ? '0' + horario.date() : horario.date()
|
||||
}/${
|
||||
horario.month() + 1 < 10
|
||||
? '0' + (horario.month() + 1)
|
||||
: horario.month() + 1
|
||||
}/${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) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
})
|
||||
.then((res) => path);
|
||||
};
|
||||
|
||||
module.exports = csv;
|
||||
@@ -1,36 +0,0 @@
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const Horario = require(`${dbPath}/Horario`);
|
||||
const GrupoHorario = require(`${dbPath}/GrupoHorario`);
|
||||
const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
|
||||
let alumnoTercerSemestre = {};
|
||||
|
||||
return TercerSemestre.findOne({
|
||||
where: { numeroCuenta },
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta alumno.');
|
||||
if (res.deseaAsistir)
|
||||
throw new Error('Ya se registro a este alumno al recorrido.');
|
||||
alumnoTercerSemestre = res;
|
||||
delete alumnoTercerSemestre.dataValues.idGrupo;
|
||||
delete alumnoTercerSemestre.dataValues.Grupo.dataValues.idCarrera;
|
||||
return GrupoHorario.findOne({
|
||||
where: { idGrupo: alumnoTercerSemestre.Grupo.idGrupo },
|
||||
include: [{ model: Horario }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
delete res.dataValues.idHorario;
|
||||
delete res.dataValues.idGrupo;
|
||||
return { alumnoTercerSemestre, GrupoHorario: res };
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -1,57 +0,0 @@
|
||||
const helperPath = '../../helper';
|
||||
const gmail = require(`${helperPath}/gmail`);
|
||||
const correos = require(`${helperPath}/correos`);
|
||||
const { validarId } = 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 registrar = async (body) => {
|
||||
const idTercerSemestre = validarId(body.idTercerSemestre);
|
||||
let alumno = {};
|
||||
let mail = {};
|
||||
|
||||
return TercerSemestre.findOne({
|
||||
where: { idTercerSemestre },
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta alumno.');
|
||||
if (res.deseaAsistir)
|
||||
throw new Error('Ya se registro a este alumno al recorrido.');
|
||||
alumno = res;
|
||||
return GrupoHorario.findOne({
|
||||
where: { idGrupo: alumno.idGrupo },
|
||||
include: [{ model: Horario }],
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
mail = correos.correoTercerSemestre(
|
||||
alumno.numeroCuenta,
|
||||
alumno.nombre,
|
||||
alumno.Grupo.Carrera.carrera,
|
||||
res.Horario.horario
|
||||
);
|
||||
return gmail(
|
||||
mail.subject,
|
||||
'lemuelhelonmarquezrosas@gmail.com',
|
||||
// `${res.numeroCuenta}@pcpuma.acatlan.unam.mx`
|
||||
mail.message
|
||||
);
|
||||
})
|
||||
.then((res) =>
|
||||
TercerSemestre.update(
|
||||
{ deseaAsistir: true },
|
||||
{ where: { idTercerSemestre } }
|
||||
)
|
||||
)
|
||||
.then((res) => ({
|
||||
message:
|
||||
'Te has registrado correctamente, hemos mandado tu comprobante a tu correo pcpuma.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = registrar;
|
||||
Reference in New Issue
Block a user