Skip to content

Instantly share code, notes, and snippets.

@cfoch
Created November 14, 2017 20:40
Show Gist options
  • Save cfoch/e19f8a3931d3ec03be8e4f72f4afecf3 to your computer and use it in GitHub Desktop.
Save cfoch/e19f8a3931d3ec03be8e4f72f4afecf3 to your computer and use it in GitHub Desktop.
getHorarios: function(object, options) {
// Yes, I feel horrrible because of this hard-coded const.
// const especialidadId = 1;
const ret = [];
const cursoId = options.params.id;
const semestreId = options.query.idSemestre;
const pageSize = options.query.pageSize,
pageIndex = Math.floor(options.query.pageIndex / pageSize + 1),
query = '%' + options.query.query + '%';
let horarios = model.knex('horario')
.select('id', 'nombre')
.where({
'curso_id': cursoId,
'semestre_id': semestreId
});
return horarios.then(data => {
//console.log(data);
data.forEach(horario => {
let item = {
idHorario: horario.id,
nombre: horario.nombre,
salones: []
};
ret.push(item);
// Llenar salones
const salonXhorario = model.knex('horario_x_salon')
.select('salon_id').where({horario_id: horario.id});
salonXhorario.then(data => {
data.forEach(salon => {
item.salones.push({
idSalon: salon.salon_id,
horarios: salon.horarios
});
});
});
});
return ret;
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment