funky-framadate-front/src/app/core/models/choice.model.ts

40 lines
1.0 KiB
TypeScript

import { Answer } from '../enums/answer.enum';
import { User } from './user.model';
export class Choice {
constructor(
public label: string,
public imageUrl?: string,
public participants: Map<Answer, Set<User>> = new Map<Answer, Set<User>>([
[Answer.YES, new Set<User>()],
[Answer.NO, new Set<User>()],
[Answer.MAYBE, new Set<User>()],
]),
public counts: Map<Answer, number> = new Map<Answer, number>([
[Answer.YES, 0],
[Answer.NO, 0],
[Answer.MAYBE, 0],
])
) {}
public updateParticipation(user: User, responseType: Answer): void {
this.removeParticipant(user);
this.participants.get(responseType).add(user);
this.updateCounts();
}
public removeParticipant(user: User): void {
for (const responseType of Object.values(Answer)) {
if (this.participants.get(responseType).has(user)) {
this.participants.get(responseType).delete(user);
}
}
}
public updateCounts(): void {
for (const responseType of Object.values(Answer)) {
this.counts.set(responseType, this.participants.get(responseType).size);
}
}
}