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;