From f67af27300630a04270551242fd31fe7fc0e97f1 Mon Sep 17 00:00:00 2001 From: yamanq Date: Tue, 9 Aug 2016 18:03:31 -0400 Subject: [PATCH] leaveClass function --- hourglass/server/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hourglass/server/main.js b/hourglass/server/main.js index aabb5c7..115579b 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -52,7 +52,7 @@ Meteor.methods({ }, 'joinClass': function(change, pass) { found = classes.find({_id: change, status: true}).fetch(); - if (Meteor.user() != null && found.length > 0 && pass === found[0].code) { + if (Meteor.user() != null && found.length > 0 && pass === found[0].code && Meteor.user().profile.classes.indexOf(change) === -1) { current = Meteor.user().profile; current.classes.append(change); Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); @@ -60,5 +60,17 @@ Meteor.methods({ } else { return 0; } + }, + 'leaveClass': function(change) { + if (Meteor.user() != null) { + profile = Meteor.user().profile + index = profile.classes.indexOf(change) + if (index >= 0) { + profile.classes.splice(index, 1); + Meteor.users.update({_id: Meteor.userId()}, {$set: {profile: current}}); + return 1 + } + + } } }); \ No newline at end of file