57 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-08-01 19:30:32 +08:00
import { Meteor } from 'meteor/meteor';
2016-08-07 00:32:19 -04:00
import { Mongo } from 'meteor/mongo';
2016-08-01 19:30:32 +08:00
2016-08-07 15:03:24 -04:00
schools = new Mongo.Collection("Schools");
classes = new Mongo.Collection("Classes");
2016-08-07 15:34:41 -04:00
work = new Mongo.Collection("Work");
2016-08-07 15:03:24 -04:00
schools.schema = new SimpleSchema({
name: {type: String},
aliases: {type: [String]}
});
classes.schema = new SimpleSchema({
school: {type: String},
//icon: {type: String},
name: {type: String, label: "Class Name"},
2016-08-07 15:21:39 -04:00
hour: {type: String, optional: true},
teacher: {type: String, optional: true},
2016-08-07 15:07:38 -04:00
status: {type: Boolean, defaultValue: false},
2016-08-07 15:03:24 -04:00
code: {type: String, optional: true},
privacy: {type: String},
category: {type: String},
2016-08-08 00:48:30 -04:00
moderators: {type: [String], optional: true},
banned: {type: [String], optional: true},
blockEdit: {type: [String], optional: true},
2016-08-07 15:21:39 -04:00
admin: {type: String}
2016-08-07 15:03:24 -04:00
});
2016-08-07 15:21:39 -04:00
work.schema = new SimpleSchema({
2016-08-07 15:03:24 -04:00
class: {type: String},
dueDate: {type: Date},
aliases: {type: [String]},
submittor: {type: String},
confirmations: {type: [String]},
reports: {type: [String], optional: true},
attachments: {type: [String], optional: true},
done: {type: [String], optional: true}
});
2016-08-08 05:39:20 -04:00
_uuid4 = function(cc) {
var rr = Math.random() * 16 | 0;
return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16);
}
2016-08-07 15:21:39 -04:00
2016-08-01 19:30:32 +08:00
Meteor.startup(() => {
2016-08-08 00:48:30 -04:00
Meteor.methods({
'genCode': function() {
2016-08-08 05:39:20 -04:00
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, _uuid4);
2016-08-08 00:48:30 -04:00
},
'createClass': function(input) {
2016-08-08 06:14:37 -04:00
if(Meteor.user() != null && Meteor.classes.find({status:true, admin:Meteor.userId()}).length < 5){
2016-08-08 00:48:30 -04:00
classes.schema.validate(input);
classes.insert(input);
}
}
})
2016-08-07 00:32:19 -04:00
});