leaveClass function

This commit is contained in:
yamanq 2016-08-09 18:03:31 -04:00
parent 62287f3f22
commit f67af27300

View File

@ -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
}
}
}
});