Skip to content

Commit

Permalink
Merge pull request #131 from Morphclue/fix/validate-error
Browse files Browse the repository at this point in the history
Fix TypeError
  • Loading branch information
Morphclue authored Feb 21, 2024
2 parents bdb611b + 4a67719 commit e69b27d
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class ChooseEventsComponent implements OnInit {
this.pollService.getEvents(id).pipe(tap(events => {
this.pollEvents = events;
this.bookedEvents = new Array(this.pollEvents.length).fill(false);
this.validateNew();
})),
this.pollService.getParticipants(id).pipe(tap(participants => this.participants = participants)),
this.pollService.isAdmin(id, this.token),
Expand All @@ -81,6 +80,7 @@ export class ChooseEventsComponent implements OnInit {
this.setDescription(poll, events, participants);

this.clearSelection();
this.validateNew();
this.bookedEvents = events.map(e => poll.bookedEvents.includes(e._id));
this.isAdmin = isAdmin;
this.updateHelpers();
Expand Down Expand Up @@ -161,9 +161,6 @@ export class ChooseEventsComponent implements OnInit {
});
}

// View Helpers
// TODO called from template, bad practice

validateNew() {
this.errors = checkParticipant(this.newParticipant, this.poll!, this.participants);
}
Expand All @@ -172,14 +169,17 @@ export class ChooseEventsComponent implements OnInit {
this.errors = checkParticipant(this.editDto!, this.poll!, this.participants, this.editParticipant!._id);
}

// View Helpers
// TODO called from template, bad practice

countParticipants(pollEvent: PollEvent) {
const participants = this.participants.filter(p => p.selection[pollEvent._id] === 'yes');
const indeterminateParticipants = this.participants.filter(p => p.selection[pollEvent._id] === 'maybe');
return participants.length + indeterminateParticipants.length;
}

userVoted() {
return this.participants.some(participant => participant.token === this.token);
isPastEvent(event: PollEvent) {
return Date.parse(event.start) < this.now;
}

// Helpers
Expand Down Expand Up @@ -216,7 +216,7 @@ export class ChooseEventsComponent implements OnInit {
return this.countParticipants(event) >= this.poll.settings.maxEventParticipants;
}

isPastEvent(event: PollEvent) {
return Date.parse(event.start) < this.now;
private userVoted() {
return this.participants.some(participant => participant.token === this.token);
}
}

0 comments on commit e69b27d

Please sign in to comment.