issue #711 closed, also update_legend has been moved from controller to model as…

issue #711 closed, also update_legend has been moved from controller to model as refactorization process
parent 2a334a11
......@@ -965,23 +965,16 @@ module.exports = {
//
update_legend: function (req, res) {
var params = req.allParams();
var query='update stu_picto'+
' set attributes=json_set(attributes, \'$.legend\',\''+params.legend_value+'\')'+
' where id_stu='+params.id_stu;
console.log('Updating legend for student ' + params.id_stu +" collection to "+
params.legend_value+": "+query);
StuPicto.query(query, function(err, result) {
if (err)
throw new Error ("error on update");
else {
console.log('Updated attributes for picto student:' + params.id_stu);
Student.update_legend(params.id_stu, params.legend_value, function (err) {
if (err) {
sails.log.debug(JSON.stringify(err));
return res.serverError("Error on legend update: ");
}
return res.ok({
id: params.id_stu,
legend_value: params.legend_value, // picto attributes for student
});
}
});
})
},
/**
......
......@@ -520,5 +520,27 @@ module.exports = {
})
.catch((err) => {cb(err)});
});
},
/*
* Updates legend in student pictos
* legend is not updated for categories
*/
update_legend: function(id_stu, legend_value, cb) {
var query='UPDATE stu_picto' +
' SET attributes = json_set(attributes, \'$.legend\',\''+legend_value+'\')' +
' WHERE id_stu=' + id_stu + ' AND ' +
' (json_extract(attributes, \'$.id_cat\') LIKE \'null\' AND ' +
' json_extract(attributes, \'$.coord_y\') = 0 OR ' +
' json_extract(attributes, \'$.id_cat\') NOT LIKE \'null\' AND ' +
' json_extract(attributes, \'$.coord_y\') > 0); '
;
StuPicto.query(query, function(err, result) {
if (err)
cb(err);
else
cb();
});
}
};
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