fixing error with null licenses

parent 710f0a3a
......@@ -70,7 +70,9 @@ module.exports = {
Class methods
*/
hasExpired: function (license) {
return (new Date(license.expiration_ts) - new Date() < 0);
if (license)
return (new Date(license.expiration_ts) - new Date() < 0);
else return true;
},
/**
......
......@@ -109,12 +109,12 @@ module.exports = {
toJSON: function () {
var student = this.toObject();
student.pic = sails.config.pictogram.urls.getStudentAvatarUrl(student.pic);
if (student.license) {
student.license = student.license[0] ? student.license[0] : null;
if (student.license && student.license[0]) {
student.license = student.license[0];
student.license.isValid = !License.hasExpired(student.license);
student.license.isTrial = student.license.type == 'trial';
student.license.isOfficial = student.license.type == 'official';
}
} else student.license = null;
student.attributes = Student.getValidAttributes(student.attributes);
student.current_method = student.lastInstruction[0] ? student.lastInstruction[0].met_name : "no_method";
student.current_instruction = student.lastInstruction[0] ? student.lastInstruction[0].ins_name : "no_instruction";
......
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