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

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-05-12 19:16:23 +02:00
import { ResponseType } from '../enums/response-type.enum';
2020-05-05 18:17:12 +02:00
export class Choice {
2020-05-12 19:16:23 +02:00
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);
}
}
2020-05-05 18:17:12 +02:00
}