Invites can now be managed to some extent

This commit is contained in:
Thaum Rystra
2020-05-12 14:11:43 +02:00
parent 47206ccfc4
commit bbda0ea1b6
8 changed files with 230 additions and 17 deletions

View File

@@ -15,6 +15,7 @@ let InviteSchema = new SimpleSchema({
regEx: SimpleSchema.RegEx.Id,
optional: true,
index: 1,
unique: 1,
},
inviteToken: {
type: String,
@@ -25,10 +26,6 @@ let InviteSchema = new SimpleSchema({
isFunded: {
type: Boolean,
},
isRedundant: {
type: Boolean,
optional: true,
},
// The timestamp of when the invitee was confirmed
// Older invites have priority over newer ones
dateConfirmed: {
@@ -119,14 +116,15 @@ const acceptInviteToken = new ValidatedMethod({
},
}).validator(),
run({inviteToken}) {
if (this.userId) {
if (!this.userId) {
throw new Meteor.Error('Invites.methods.acceptToken.denied',
'You need to be the logged in to accept a token');
}
if (Meteor.isClient) return;
let invite = Invites.findOne({inviteToken});
if (!invite){
throw new Meteor.Error('Invites.methods.acceptToken.notFound',
'No invite could be found for this token');
'No invite could be found for this link, maybe it has already been claimed');
}
// If the invitee is already filled, fix unexpected case by deleting the token
if (invite.invitee){
@@ -134,7 +132,7 @@ const acceptInviteToken = new ValidatedMethod({
$unset: {inviteToken: 1}
});
throw new Meteor.Error('Invites.methods.acceptToken.alreadyAccepted',
'This invite already has an invitee, and shouldn\'t have a token');
'This invite has already been claimed');
}
if (this.userId === invite.inviter){
throw new Meteor.Error('Invites.methods.acceptToken.ownToken',