Skip to content

Commit

Permalink
refactor: small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed May 25, 2024
1 parent 04df116 commit f7c7bb0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface Client {
}

export interface Vote {
event: string;
answer: 'a' | 'b';
createdAt: Date;
}
Expand All @@ -19,7 +18,10 @@ export class EventsService {
(acc, event) => ({ ...acc, [event.name]: { action: null } }),
{},
);
private votes: Vote[] = [];
private votes: Record<string, Vote[]> = events.reduce(
(acc, event) => ({ ...acc, [event.name]: [] }),
{},
);

constructor() {
events.forEach((event) => this.scheduleNewAction(event.name));
Expand Down Expand Up @@ -76,10 +78,10 @@ export class EventsService {
}

addVote(event: string, answer: 'a' | 'b') {
this.votes.push({ event, answer, createdAt: new Date() });
this.votes[event].push({ answer, createdAt: new Date() });
}

getVotes(event: string) {
return this.votes.filter((vote) => vote.event === event);
return this.votes[event];
}
}

0 comments on commit f7c7bb0

Please sign in to comment.