teacher collection
This commit is contained in:
parent
3fef965cce
commit
941510c931
@ -3,9 +3,10 @@ classes = new Mongo.Collection("Classes");
|
||||
work = new Mongo.Collection("Work");
|
||||
requests = new Mongo.Collection("Requests");
|
||||
admins = Meteor.users;
|
||||
teachers = new Mongo.Collection("Teachers");
|
||||
|
||||
schools.schema = new SimpleSchema({
|
||||
name: {type: String},
|
||||
name: {type: String}
|
||||
});
|
||||
|
||||
classes.schema = new SimpleSchema({
|
||||
@ -56,7 +57,13 @@ userSchema = new SimpleSchema({
|
||||
'profile.classes': {type: [String], label: "Classes"}
|
||||
});
|
||||
|
||||
teachers.schema = new SimpleSchema({
|
||||
name: {type: String},
|
||||
school: {type: String}
|
||||
});
|
||||
|
||||
schools.attachSchema(schools.schema);
|
||||
classes.attachSchema(classes.schema);
|
||||
work.attachSchema(work.schema);
|
||||
requests.attachSchema(requests.schema);
|
||||
teachers.attachSchema(teachers.schema);
|
||||
|
||||
@ -149,9 +149,10 @@ var errors = [
|
||||
["trivial", "This request is too long."],
|
||||
["trivial", "Not a valid work type"],
|
||||
["unauthorized", "This class has not been approved yet"],
|
||||
["matching", "This teacher already exists"],
|
||||
|
||||
["unauthorized", "Sorry, you are not authorized to complete this action."],
|
||||
["other", "Error could not be processed"]
|
||||
["unauthorized", "Sorry, you are not authorized to complete this action."], // n - 2
|
||||
["other", "Error could not be processed"] // n - 1
|
||||
];
|
||||
|
||||
function securityCheck(checklist, input) {
|
||||
@ -182,7 +183,6 @@ function securityCheck(checklist, input) {
|
||||
case 3:
|
||||
if (!schools.findOne({name: input.school})) error = 2;
|
||||
break;
|
||||
// TODO: teachers with same name
|
||||
// Duplicate classes
|
||||
case 4:
|
||||
if (classes.findOne({school: input.school, status: true, privacy: false, teacher: input.teacher, hour: input.hour}) || (input.teacher === "" && input.hour === "")) error = 3;
|
||||
@ -266,6 +266,10 @@ function securityCheck(checklist, input) {
|
||||
case 25:
|
||||
if (Meteor.userId() === null) error = errors.length - 1;
|
||||
break;
|
||||
// New Teacher doesn't already exist
|
||||
case 26:
|
||||
if (teachers.find({name: input.teacherName, school: input.school}).fetch().length > 0) error = 19;
|
||||
break;
|
||||
}
|
||||
results.push(error);
|
||||
}
|
||||
@ -782,5 +786,16 @@ Meteor.methods({
|
||||
} else {
|
||||
throw new Meteor.Error(errors[security]);
|
||||
}
|
||||
},
|
||||
'createTeacher': function(teacherName, schoolName) {
|
||||
var security = securityCheck([26, 3, true], {teachername: teacherName, school: schoolName});
|
||||
if (!security) {
|
||||
teachers.insert({
|
||||
name: teacherName,
|
||||
school: schoolName
|
||||
});
|
||||
} else {
|
||||
throw new Meteor.Error(errors[security]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user