From 941510c9312ae5adf2656d8f0e8bdb044272f5ba Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Mon, 7 Nov 2016 21:34:30 -0500 Subject: [PATCH] teacher collection --- hourglass/collections/main.js | 9 ++++++++- hourglass/server/main.js | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/hourglass/collections/main.js b/hourglass/collections/main.js index 7cfa5be..697e2c6 100644 --- a/hourglass/collections/main.js +++ b/hourglass/collections/main.js @@ -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); diff --git a/hourglass/server/main.js b/hourglass/server/main.js index db1ec44..de66d24 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -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]); + } } });