teacher collection

This commit is contained in:
Yaman Qalieh 2016-11-07 21:34:30 -05:00
parent 3fef965cce
commit 941510c931
2 changed files with 26 additions and 4 deletions

View File

@ -3,9 +3,10 @@ classes = new Mongo.Collection("Classes");
work = new Mongo.Collection("Work"); work = new Mongo.Collection("Work");
requests = new Mongo.Collection("Requests"); requests = new Mongo.Collection("Requests");
admins = Meteor.users; admins = Meteor.users;
teachers = new Mongo.Collection("Teachers");
schools.schema = new SimpleSchema({ schools.schema = new SimpleSchema({
name: {type: String}, name: {type: String}
}); });
classes.schema = new SimpleSchema({ classes.schema = new SimpleSchema({
@ -56,7 +57,13 @@ userSchema = new SimpleSchema({
'profile.classes': {type: [String], label: "Classes"} 'profile.classes': {type: [String], label: "Classes"}
}); });
teachers.schema = new SimpleSchema({
name: {type: String},
school: {type: String}
});
schools.attachSchema(schools.schema); schools.attachSchema(schools.schema);
classes.attachSchema(classes.schema); classes.attachSchema(classes.schema);
work.attachSchema(work.schema); work.attachSchema(work.schema);
requests.attachSchema(requests.schema); requests.attachSchema(requests.schema);
teachers.attachSchema(teachers.schema);

View File

@ -149,9 +149,10 @@ var errors = [
["trivial", "This request is too long."], ["trivial", "This request is too long."],
["trivial", "Not a valid work type"], ["trivial", "Not a valid work type"],
["unauthorized", "This class has not been approved yet"], ["unauthorized", "This class has not been approved yet"],
["matching", "This teacher already exists"],
["unauthorized", "Sorry, you are not authorized to complete this action."], ["unauthorized", "Sorry, you are not authorized to complete this action."], // n - 2
["other", "Error could not be processed"] ["other", "Error could not be processed"] // n - 1
]; ];
function securityCheck(checklist, input) { function securityCheck(checklist, input) {
@ -182,7 +183,6 @@ function securityCheck(checklist, input) {
case 3: case 3:
if (!schools.findOne({name: input.school})) error = 2; if (!schools.findOne({name: input.school})) error = 2;
break; break;
// TODO: teachers with same name
// Duplicate classes // Duplicate classes
case 4: case 4:
if (classes.findOne({school: input.school, status: true, privacy: false, teacher: input.teacher, hour: input.hour}) || (input.teacher === "" && input.hour === "")) error = 3; 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: case 25:
if (Meteor.userId() === null) error = errors.length - 1; if (Meteor.userId() === null) error = errors.length - 1;
break; 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); results.push(error);
} }
@ -782,5 +786,16 @@ Meteor.methods({
} else { } else {
throw new Meteor.Error(errors[security]); 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]);
}
} }
}); });