formatted code
This commit is contained in:
parent
4f67ff8194
commit
513e19046c
@ -1,5 +1,9 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import {
|
||||||
import { Mongo } from 'meteor/mongo';
|
Meteor
|
||||||
|
} from 'meteor/meteor';
|
||||||
|
import {
|
||||||
|
Mongo
|
||||||
|
} from 'meteor/mongo';
|
||||||
|
|
||||||
_uuid4 = function(cc) {
|
_uuid4 = function(cc) {
|
||||||
var rr = Math.random() * 16 | 0;
|
var rr = Math.random() * 16 | 0;
|
||||||
@ -14,22 +18,38 @@ Meteor.methods({
|
|||||||
'createSchool': function(schoolname) {
|
'createSchool': function(schoolname) {
|
||||||
// if superadmin, no need for approval
|
// if superadmin, no need for approval
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
schools.findOne({name:input.school}) !== null &&
|
schools.findOne({
|
||||||
schools.findOne({status: false, creator: Meteor.userId()}) !== null) {
|
name: input.school
|
||||||
|
}) !== null &&
|
||||||
|
schools.findOne({
|
||||||
|
status: false,
|
||||||
|
creator: Meteor.userId()
|
||||||
|
}) !== null) {
|
||||||
|
|
||||||
schools.insert({name: schoolname, status: false, creator: Meteor.userId()});
|
schools.insert({
|
||||||
|
name: schoolname,
|
||||||
|
status: false,
|
||||||
|
creator: Meteor.userId()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'deleteSchool': function(schoolid) {
|
'deleteSchool': function(schoolid) {
|
||||||
// alanning:roles implementation here
|
// alanning:roles implementation here
|
||||||
schools.remove({_id: schoolid});
|
schools.remove({
|
||||||
|
_id: schoolid
|
||||||
|
});
|
||||||
},
|
},
|
||||||
'createClass': function(input) {
|
'createClass': function(input) {
|
||||||
// if superadmin, no need for approval
|
// if superadmin, no need for approval
|
||||||
classes.schema.validate(input);
|
classes.schema.validate(input);
|
||||||
if(Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
classes.find({status:false, admin:Meteor.userId()}).fetch().length < 5 &&
|
classes.find({
|
||||||
schools.findOne({name:input.school}) !== null) {
|
status: false,
|
||||||
|
admin: Meteor.userId()
|
||||||
|
}).fetch().length < 5 &&
|
||||||
|
schools.findOne({
|
||||||
|
name: input.school
|
||||||
|
}) !== null) {
|
||||||
|
|
||||||
input.status = false;
|
input.status = false;
|
||||||
input.subscribers = 0;
|
input.subscribers = 0;
|
||||||
@ -48,25 +68,31 @@ Meteor.methods({
|
|||||||
input.banned = [];
|
input.banned = [];
|
||||||
input.blockEdit = [];
|
input.blockEdit = [];
|
||||||
classes.insert(input);
|
classes.insert(input);
|
||||||
Meteor.call('joinClass',classes.findOne(input)._id, input.code, function(error,result){});
|
Meteor.call('joinClass', classes.findOne(input)._id, input.code, function(error, result) {});
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'deleteClass': function(classid) {
|
'deleteClass': function(classid) {
|
||||||
found = classes.findOne({_id: classid});
|
found = classes.findOne({
|
||||||
|
_id: classid
|
||||||
|
});
|
||||||
// Add roles
|
// Add roles
|
||||||
if (Meteor.user() !== null && found !== null && found.admin === Meteor.user()._id) {
|
if (Meteor.user() !== null && found !== null && found.admin === Meteor.user()._id) {
|
||||||
classes.remove({_id: classid});
|
classes.remove({
|
||||||
|
_id: classid
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'createWork': function(input) {
|
'createWork': function(input) {
|
||||||
ref = new Date();
|
ref = new Date();
|
||||||
month = ref.getMonth + 1;
|
month = ref.getMonth + 1;
|
||||||
ref = new Date(ref.getFullYear()+ "-" + month.toString() + "-" + ref.getDate()).getTime();
|
ref = new Date(ref.getFullYear() + "-" + month.toString() + "-" + ref.getDate()).getTime();
|
||||||
work.schema.validate(input);
|
work.schema.validate(input);
|
||||||
found = Meteor.findOne({_id: input.class});
|
found = Meteor.findOne({
|
||||||
|
_id: input.class
|
||||||
|
});
|
||||||
|
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
found !== null &&
|
found !== null &&
|
||||||
@ -87,7 +113,9 @@ Meteor.methods({
|
|||||||
},
|
},
|
||||||
'deleteWork': function(workid) {
|
'deleteWork': function(workid) {
|
||||||
// Add security here
|
// Add security here
|
||||||
work.remove({_id: workid});
|
work.remove({
|
||||||
|
_id: workid
|
||||||
|
});
|
||||||
},
|
},
|
||||||
'editProfile': function(change) {
|
'editProfile': function(change) {
|
||||||
current = Meteor.user().profile;
|
current = Meteor.user().profile;
|
||||||
@ -97,12 +125,20 @@ Meteor.methods({
|
|||||||
current.avatar = change.avatar;
|
current.avatar = change.avatar;
|
||||||
current.banner = change.banner;
|
current.banner = change.banner;
|
||||||
current.preferences = change.preferences;
|
current.preferences = change.preferences;
|
||||||
if (schools.findOne({name:current.school}) !== null &&
|
if (schools.findOne({
|
||||||
|
name: current.school
|
||||||
|
}) !== null &&
|
||||||
Number.isInteger(current.grade) &&
|
Number.isInteger(current.grade) &&
|
||||||
current.grade >= 9 && current.grade <= 12 &&
|
current.grade >= 9 && current.grade <= 12 &&
|
||||||
current.description.length <= 50) {
|
current.description.length <= 50) {
|
||||||
|
|
||||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
Meteor.users.update({
|
||||||
|
_id: Meteor.userId()
|
||||||
|
}, {
|
||||||
|
$set: {
|
||||||
|
profile: current
|
||||||
|
}
|
||||||
|
});
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -112,13 +148,22 @@ Meteor.methods({
|
|||||||
change = input[0];
|
change = input[0];
|
||||||
pass = input[1];
|
pass = input[1];
|
||||||
|
|
||||||
if(Meteor.user().profile.classes === undefined) {
|
if (Meteor.user().profile.classes === undefined) {
|
||||||
curr = Meteor.user().profile;
|
curr = Meteor.user().profile;
|
||||||
curr.classes = [];
|
curr.classes = [];
|
||||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: curr}});
|
Meteor.users.update({
|
||||||
|
_id: Meteor.userId()
|
||||||
|
}, {
|
||||||
|
$set: {
|
||||||
|
profile: curr
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
prof = Meteor.user().profile;
|
prof = Meteor.user().profile;
|
||||||
found = classes.findOne({_id: change, status: true});
|
found = classes.findOne({
|
||||||
|
_id: change,
|
||||||
|
status: true
|
||||||
|
});
|
||||||
if (Meteor.user() !== null &&
|
if (Meteor.user() !== null &&
|
||||||
found !== null &&
|
found !== null &&
|
||||||
pass === found.code &&
|
pass === found.code &&
|
||||||
@ -127,7 +172,13 @@ Meteor.methods({
|
|||||||
|
|
||||||
current = Meteor.user().profile;
|
current = Meteor.user().profile;
|
||||||
current.classes.append(change);
|
current.classes.append(change);
|
||||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
Meteor.users.update({
|
||||||
|
_id: Meteor.userId()
|
||||||
|
}, {
|
||||||
|
$set: {
|
||||||
|
profile: current
|
||||||
|
}
|
||||||
|
});
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -138,9 +189,17 @@ Meteor.methods({
|
|||||||
profile = Meteor.user().profile;
|
profile = Meteor.user().profile;
|
||||||
index = profile.classes.indexOf(change);
|
index = profile.classes.indexOf(change);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
if (classes.findOne({_id: change}).admin != Meteor.userId()) {
|
if (classes.findOne({
|
||||||
|
_id: change
|
||||||
|
}).admin != Meteor.userId()) {
|
||||||
profile.classes.splice(index, 1);
|
profile.classes.splice(index, 1);
|
||||||
Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}});
|
Meteor.users.update({
|
||||||
|
_id: Meteor.userId()
|
||||||
|
}, {
|
||||||
|
$set: {
|
||||||
|
profile: current
|
||||||
|
}
|
||||||
|
});
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} 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.";
|
||||||
@ -152,8 +211,8 @@ Meteor.methods({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function has(array, has) {
|
function has(array, has) {
|
||||||
for(var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
if(array[i] === has) return true;
|
if (array[i] === has) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user