Vulcan/server/invites.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-10-23 19:43:42 +09:00
Meteor.methods({
inviteUser: function (userId) {
var currentUser = Meteor.user();
var invitedUser = Meteor.users.findOne(userId);
var invite = {
invited: invitedUser._id,
invitedName: getDisplayName(invitedUser),
time: new Date()
};
// if the current user is logged in, still has available invites and is himself invited (or an admin), and the target user is not invited
if(currentUser && currentUser.invitesCount > 0 && canInvite(currentUser) && !isInvited(invitedUser)){
// update invinting user
Meteor.users.update(Meteor.userId(), {$inc:{invitesCount: -1}});
Meteor.users.update(Meteor.userId(), {$push:{invites: invite}});
// update invited user
Meteor.users.update(userId, {$set: {
isInvited: true,
invitedBy: currentUser._id,
invitedByName: getDisplayName(currentUser)
}});
2013-10-23 20:20:10 +09:00
Meteor.call('createNotification', {
event: 'accountApproved',
properties: {},
2013-10-23 20:27:19 +09:00
userToNotify: invitedUser,
userDoingAction: currentUser,
2013-10-23 20:20:10 +09:00
sendEmail: true
});
2013-10-23 19:43:42 +09:00
}else{
throw new Meteor.Error(701, "You can't invite this user, sorry.");
}
}
})