39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { ResponseType } from '../enums/response-type.enum';
|
|
|
|
export class Choice {
|
|
constructor(
|
|
public label: string,
|
|
public imageUrl?: string,
|
|
public participants: Map<ResponseType, Set<string>> = new Map<ResponseType, Set<string>>([
|
|
[ResponseType.YES, new Set<string>()],
|
|
[ResponseType.NO, new Set<string>()],
|
|
[ResponseType.MAYBE, new Set<string>()],
|
|
]),
|
|
public counts: Map<ResponseType, number> = new Map<ResponseType, number>([
|
|
[ResponseType.YES, 0],
|
|
[ResponseType.NO, 0],
|
|
[ResponseType.MAYBE, 0],
|
|
])
|
|
) {}
|
|
|
|
public updateParticipation(pseudo: string, responseType: ResponseType): void {
|
|
this.removeParticipant(pseudo);
|
|
this.participants.get(responseType).add(pseudo);
|
|
this.updateCounts();
|
|
}
|
|
|
|
public removeParticipant(pseudo: string): void {
|
|
for (const responseType of Object.values(ResponseType)) {
|
|
if (this.participants.get(responseType).has(pseudo)) {
|
|
this.participants.get(responseType).delete(pseudo);
|
|
}
|
|
}
|
|
}
|
|
|
|
public updateCounts(): void {
|
|
for (const responseType of Object.values(ResponseType)) {
|
|
this.counts.set(responseType, this.participants.get(responseType).size);
|
|
}
|
|
}
|
|
}
|