This commit is contained in:
Kenneth Jao 2016-08-20 23:37:17 -04:00
commit e5012e3c04
3 changed files with 38 additions and 3 deletions

View File

@ -1,6 +1,7 @@
schools = new Mongo.Collection("Schools");
classes = new Mongo.Collection("Classes");
work = new Mongo.Collection("Work");
requests = new Mongo.Collection("Requests");
schools.schema = new SimpleSchema({
name: {type: String},
@ -37,3 +38,9 @@ work.schema = new SimpleSchema({
done: {type: [String], optional: true},
type: {type: String}
});
requests.schema = new SimpleSchema({
requestor: {type: String},
request: {type: String},
timeRequested: {type: Date}
});

View File

@ -7,6 +7,7 @@ Router.route('/', {
Meteor.subscribe('classes',this.params._id),
Meteor.subscribe('schools',this.params._id),
Meteor.subscribe('work',this.params._id),
Meteor.subscribe('requests',this.params._id),
Meteor.subscribe('users',this.params._id)
];
}
@ -35,6 +36,7 @@ Router.route('/profile', {
Meteor.subscribe('classes',this.params._id),
Meteor.subscribe('schools',this.params._id),
Meteor.subscribe('work',this.params._id),
Meteor.subscribe('requests',this.params._id),
Meteor.subscribe('users',this.params._id)
];
}

View File

@ -72,6 +72,14 @@ Meteor.publish('work', function() {
});
Meteor.publish('requests', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return requests.find();
} else {
return requests.find({requestor: this.userId});
}
});
Meteor.publish('users', function() {
if (Roles.userIsInRole(this.userId, ['superadmin', 'admin'])) {
return Meteor.users.find();
@ -89,7 +97,9 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w
Meteor.methods({
'genCode': function() {
currcode = Math.random().toString(36).substr(2, 6);
while (classes.findOne({code: currcode}) !== undefined) {
while (classes.findOne({
code: currcode
}) !== undefined) {
currcode = Math.random().toString(36).substr(2, 6);
}
return currcode;
@ -268,7 +278,7 @@ Meteor.methods({
},
'createWork': function(input) {
var ref = new Date();
ref.setHours(0,0,0,0);
ref.setHours(0, 0, 0, 0);
ref = ref.getTime();
input.creator = Meteor.userId();
work.schema.validate(input);
@ -295,7 +305,7 @@ Meteor.methods({
},
'editWork': function(change) {
var ref = new Date();
ref.setHours(0,0,0,0);
ref.setHours(0, 0, 0, 0);
ref = ref.getTime();
var currentclass = classes.findOne({
_id: work.findOne({
@ -532,6 +542,8 @@ Meteor.methods({
}
}
} else {
throw "Unauthorized";
}
},
'createAdmin': function(userId) {
@ -543,5 +555,19 @@ Meteor.methods({
if (Roles.userIsInRole(Meteor.user()._id, ['superadmin'])) {
Roles.removeUsersToRoles(userId, ['admin']);
}
},
'createRequest': function(request) {
if (request.length <= 500 && Meteor.userId() !== null) {
requests.insert({
requestor: Meteor.userId(),
request: request,
timeRequested: new Date()
});
}
},
'deleteRequest': function(requestId) {
if (Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin'])) {
requests.remove({_id: requestId});
}
}
});