Working on issue #588

parent dc05f9d3
Showing with 69 additions and 17 deletions
......@@ -452,23 +452,70 @@ module.exports = {
var l_met = [];
Method.find({ id_stu: id_stu }).exec(function(err, methods) {
Method.find({ id_stu: id_stu })
.populate('instructions')
.then((methods) => {
if (!methods || methods.length == 0)
return callback([]);
// Recorremos methods
async.eachSeries(methods,
function(method, next_met) {
if (!method.instructions || method.instructions.length == 0)
next_met();
var l_ws = [];
// Recorremos instructions
async.eachSeries(method.instructions,
function (instruction, next_inst) {
Instruction.findOne({id: instruction})
.populate('workingSessions')
.then((instruction) => {
if (!instruction)
return next_inst();
if (!instruction.workingSessions || instruction.workingSessions.length == 0)
return next_inst();
// Recorremos workingSessions
var l_try = [];
async.eachSeries(instruction.workingSessions,
function(ws, next_ws) {
WorkingSession.findOne({id: ws.id})
.populate(tries)
.then((found_ws) => {
if (!found_ws || !found_ws.tries || found_ws.tries_length == 0)
return next_ws();
// POR FIN!!! Tenemos un método, una instrucción, una working session y sus tries
l_try = found_ws.tries;
})
},
function(err) {
if (err)
return next_ws();
next_inst();
});
})
.catch(err => {
if (err || !methods || methods.length == 0)
return callback(err, []);
});
})
.catch((err) => {
next_inst();
});
},
function (err) {
}
);
// eachSeries
async.eachSeries(
// 1st array of items
methods,
// 2nd function to operate over one item
function(method, next) {
// Original: Devolver el objeto con el método completo / instructions / workinSessions / Tries
// y controlar en Angular
//Instruction.find({ id_met: method.id }).populate('tries').exec(function(err, instructions) {
Instruction.find({ id_met: method.id }).populate('workingSessions').exec(function(err, instructions) {
if (err || !instructions || instructions.length == 0)
console.log("error finding instructions");
.populate('workingSessions')
.then((instructions) {
if (instructions && instructions.length == 0)
// Push method
l_met.push({
......@@ -481,7 +528,7 @@ module.exports = {
"instructions": instructions,
});
next();
next_met();
});
},
......@@ -494,8 +541,13 @@ module.exports = {
// with the list
}
);
});
})
.catch((err) => {
if (err)
return callback(err, []);
});
},
// Removes logically a student
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment