24 lines
682 B
JavaScript
24 lines
682 B
JavaScript
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;
|