issue #511 resolved

parent 01353467
Showing with 65 additions and 33 deletions
...@@ -274,7 +274,7 @@ module.exports = { ...@@ -274,7 +274,7 @@ module.exports = {
// //
// Class method for getting the list of therapists associated to a given // Class method for getting the list of therapists associated to a given
// student // student
// NOTE: A therapist is a supervisor assigned to an office // NOTE: A therapist is a supervisor assigned to an office
therapists: function(id_stu, callback) { therapists: function(id_stu, callback) {
StuSup.find({id_stu: id_stu}).populate('supervisor').exec(function(err, stuSups) { StuSup.find({id_stu: id_stu}).populate('supervisor').exec(function(err, stuSups) {
var l = []; var l = [];
...@@ -328,43 +328,75 @@ module.exports = { ...@@ -328,43 +328,75 @@ module.exports = {
// Class method for getting the list of pictos associated to a given // Class method for getting the list of pictos associated to a given
// student // student
pictos: function(id_stu, callback) { pictos: function(id_stu, callback) {
Student.findOne(id_stu).exec(function(err, student) { var l = [];
if (student){
Student.findOne(id_stu)
StuPicto.find({student: id_stu}).populate('picto').exec(function(err, stuPictos) { .then((student) => {
if (!student)
var l = []; throw new Error("No student found");
if (err || !stuPictos || stuPictos.length == 0) var stuPictos = StuPicto.find({student: id_stu})
return callback(err, l); .populate('picto')
.then((stuPictos) => {
async.eachSeries(stuPictos, function(stuPicto, cb) { if (!stuPictos || stuPictos.length == 0)
return [];
return stuPictos;
})
.catch((err) => {
throw err;
});
// Populate expressions to get it with the picto return [student, stuPictos];
Picto.findOne(stuPicto.picto.id) })
.populate('expressions', {lang: student.lang}) .spread((student, stuPictos) => {
.exec(function(err, picto) { async.eachSeries(stuPictos, function(stuPicto, next_cb) {
if (err) throw err;
var stuPictoToAdd = { // Populate expressions to get it with the picto
"id": stuPicto.id, Picto.findOne(stuPicto.picto.id)
"picto": stuPicto.picto, .populate('expressions', {lang: student.lang})
"expression": picto.expressions[0], .then((picto) => {
"attributes": stuPicto.attributes
};
l.push(stuPictoToAdd); // check picto has expressions associated in student language
if (picto.expressions.length == 0 || picto.expressions[0].text.length == 0) {
sails.log.debug("No expression for picto " + picto.id);
return;
}
cb(); // next in the series // check picto image is available
}); var fs = require('fs');
}, var img_path = sails.config.pictogram.paths.public + stuPicto.picto.uri;
function(err) { fs.access(img_path, fs.F_OK, function(err) {
callback(err, l); // out loop finished, return result if (err) {
sails.log.debug("No image file for " + img_path);
return;
}
// Now we have everythin, so we add the picto to the list
var stuPictoToAdd = {
"id": stuPicto.id,
"picto": stuPicto.picto,
"expression": picto.expressions[0],
"attributes": stuPicto.attributes
};
l.push(stuPictoToAdd);
}); });
})
}); .catch((err) => {
} sails.log.debug("Error found obtaining pictos: " + err);
}); })
.then(() => next_cb()); // end Picto.findOne
},
function (err) { // loop has end
if (err)
sails.log.debug("Error found obtaining pictos: " + err);
callback(err, l);
}); // end async.eachSeries
})
.catch((err) => {
sails.log.debug("Error found obtaining pictos: " + err);
callback(err, l);
}); // end Student.findOne
}, },
// //
......
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