casi terminada
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const Premiacion = require('../../db/tablas/Premiacion');
|
||||
|
||||
const get = () => Premiacion.findAll();
|
||||
const get = () => Premiacion.findAll({where: {activa: true}});
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -13,19 +13,29 @@ const cargaMasiva = async (file, body) => {
|
||||
.fromFile(path)
|
||||
.then(async (profesores) => {
|
||||
for (let i = 0; i < profesores.length; i++) {
|
||||
const resp = await Profesor.create({
|
||||
numeroTrabajador: profesores[i].numeroTrabajador,
|
||||
nombre: profesores[i].nombre,
|
||||
correo: `${profesores[i].numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
adscripcion: profesores[i].adscripcion,
|
||||
let profesor = await Profesor.findOne({
|
||||
where: { numeroTrabajador: profesores[i].numeroTrabajador },
|
||||
});
|
||||
res.push(resp);
|
||||
let resp;
|
||||
|
||||
if (!profesor) {
|
||||
resp = await Profesor.create({
|
||||
numeroTrabajador: profesores[i].numeroTrabajador,
|
||||
nombre: profesores[i].nombre,
|
||||
correo: `${profesores[i].numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
adscripcion: profesores[i].adscripcion,
|
||||
});
|
||||
}
|
||||
|
||||
profesor ? res.push(profesor) : res.push(resp);
|
||||
|
||||
await ProfesorPremiacion.create({
|
||||
idPremiacion,
|
||||
idProfesor: resp.idProfesor,
|
||||
idProfesor: profesor ? profesor.idProfesor : resp.idProfesor,
|
||||
numeroInvitados: null,
|
||||
numeroInvitadosDentro: null,
|
||||
});
|
||||
profesor = null;
|
||||
}
|
||||
await eliminarArchivo(path);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const Premiacion = require('../../db/tablas/Premiacion');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const ProfesorPremiacion = require('../../db/tablas/ProfesorPremiacion');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const premiaciones = async (query) => {
|
||||
const idProfesor = validar.validarNumeroEntero(
|
||||
query.idProfesor,
|
||||
'idProfesor'
|
||||
);
|
||||
const premiaciones = [];
|
||||
|
||||
const profesor = await Profesor.findOne({ where: idProfesor });
|
||||
if (!profesor) throw new Error('Este profesor no existe.');
|
||||
|
||||
const res = await ProfesorPremiacion.findAll({
|
||||
where: { idProfesor },
|
||||
});
|
||||
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'Este profesor no está registrado en ninguna entrega de medallas.'
|
||||
);
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let resp = await Premiacion.findOne({ where: res[i].idPremiacion });
|
||||
premiaciones[i] = resp.dataValues;
|
||||
}
|
||||
return premiaciones;
|
||||
};
|
||||
|
||||
module.exports = premiaciones;
|
||||
Reference in New Issue
Block a user