diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 826e3f9..7fae929 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -4,7 +4,7 @@ import { Mongo } from 'meteor/mongo'; _uuid4 = function(cc) { var rr = Math.random() * 16 | 0; return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16); -} +}; worktype = ["test", "quiz", "project", "normal"]; Meteor.methods({ @@ -13,27 +13,27 @@ Meteor.methods({ }, 'createSchool': function(schoolname) { // if superadmin, no need for approval - if (Meteor.user() != null && - schools.findOne({name:input.school}) != null && - schools.findOne({status: false, creator: Meteor.userId()}) != null) { + if (Meteor.user() !== null && + schools.findOne({name:input.school}) !== null && + schools.findOne({status: false, creator: Meteor.userId()}) !== null) { schools.insert({name: schoolname, status: false, creator: Meteor.userId()}); } }, 'deleteSchool': function(schoolid) { // alanning:roles implementation here - schools.remove({_id: schoolid}) + schools.remove({_id: schoolid}); }, 'createClass': function(input) { // if superadmin, no need for approval classes.schema.validate(input); - if(Meteor.user() != null && + if(Meteor.user() !== null && classes.find({status:false, admin:Meteor.userId()}).fetch().length < 5 && - schools.findOne({name:input.school}) != null) { + schools.findOne({name:input.school}) !== null) { input.status = false; input.subscribers = 0; - input.admin = Meteor.userId() + input.admin = Meteor.userId(); if (input.privacy) { Meteor.call('genCode', function(error, result) { input.code = result; @@ -44,9 +44,9 @@ Meteor.methods({ if (input.category != "class" && input.category != "club") { input.category = "other"; } - input.moderators = [] - input.banned = [] - input.blockEdit = [] + input.moderators = []; + input.banned = []; + input.blockEdit = []; classes.insert(input); Meteor.call('joinClass',classes.findOne(input)._id, input.code, function(error,result){}); return 1; @@ -57,19 +57,19 @@ Meteor.methods({ 'deleteClass': function(classid) { found = classes.findOne({_id: classid}); // Add roles - if (Meteor.user() != null && found != null && found.admin === Meteor.user()._id) { - classes.remove({_id: classid}) + if (Meteor.user() !== null && found !== null && found.admin === Meteor.user()._id) { + classes.remove({_id: classid}); } }, 'createWork': function(input) { - ref = new Date() - month = ref.getMonth +1 - ref = new Date(ref.getFullYear()+ "-" + month.toString() + "-" + ref.getDate()).getTime() + ref = new Date(); + month = ref.getMonth + 1; + ref = new Date(ref.getFullYear()+ "-" + month.toString() + "-" + ref.getDate()).getTime(); work.schema.validate(input); - found = Meteor.findOne({_id: input.class}) + found = Meteor.findOne({_id: input.class}); - if (Meteor.user() != null && - found != null && + if (Meteor.user() !== null && + found !== null && found.subscribers.indexOf(Meteor.userId()) != -1 && found.banned.indexOf(Meteor.userId()) === -1 && found.blockEdit.indexOf(Meteor.userId()) === -1 && @@ -96,8 +96,8 @@ Meteor.methods({ current.description = change.description; current.avatar = change.avatar; current.banner = change.banner; - current.preferences = change.preferences - if (schools.findOne({name:current.school}) != null && + current.preferences = change.preferences; + if (schools.findOne({name:current.school}) !== null && Number.isInteger(current.grade) && current.grade >= 9 && current.grade <= 12 && current.description.length <= 50) { @@ -115,12 +115,12 @@ Meteor.methods({ if(Meteor.user().profile.classes === undefined) { curr = Meteor.user().profile; curr.classes = []; - Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: curr}}) + Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: curr}}); } prof = Meteor.user().profile; found = classes.findOne({_id: change, status: true}); - if (Meteor.user() != null && - found != null && + if (Meteor.user() !== null && + found !== null && pass === found.code && !found.banned.includes(Meteor.userId()) && !prof.classes.includes(change)) { @@ -134,16 +134,16 @@ Meteor.methods({ } }, 'leaveClass': function(change) { - if (Meteor.user() != null) { - profile = Meteor.user().profile - index = profile.classes.indexOf(change) + if (Meteor.user() !== null) { + profile = Meteor.user().profile; + index = profile.classes.indexOf(change); if (index >= 0) { if (classes.findOne({_id: change}).admin != Meteor.userId()) { profile.classes.splice(index, 1); Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); - return 1 + return 1; } else { - throw "You are currently the admin of this class. Transfer ownership in order to leave this class." + throw "You are currently the admin of this class. Transfer ownership in order to leave this class."; } } @@ -156,4 +156,4 @@ function has(array, has) { if(array[i] === has) return true; } return false; -} \ No newline at end of file +}