Merge pull request #7 from jcreek/1-add-estimate-option-for-not-choosing-a-number-eg

feat(#1): Add estimate option for not choosing a number
This commit is contained in:
Josh Creek
2023-07-13 21:01:44 +01:00
committed by GitHub
7 changed files with 10 additions and 34 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ export class Room {
}
getAllEstimates() {
const estimates = new Map<string, number>();
const estimates = new Map<string, number | string>();
this.users.forEach((user) => {
if (user.estimate !== null) {
estimates.set(user.name, user.estimate);
+1 -1
View File
@@ -1,7 +1,7 @@
export class User {
userId: string;
name: string;
estimate: number | null;
estimate: number | string | null;
constructor(userId: string, name: string) {
this.userId = userId;
@@ -2,9 +2,9 @@ export class SelectEstimateMessage {
type: string;
roomId: string;
userId: string;
estimate: number;
estimate: number | string;
constructor(roomId: string, userId: string, estimate: number) {
constructor(roomId: string, userId: string, estimate: number | string) {
this.type = 'select-estimate';
this.roomId = roomId;
this.userId = userId;
+1 -13
View File
@@ -17,18 +17,8 @@ function onSocketPostError(e: Error) {
console.log(e);
}
function calculateAverageEstimate(users: Array<User>) {
let total = 0;
users.forEach((user) => {
if (user.estimate !== null) {
total += user.estimate;
}
});
return total / users.length;
}
function groupEstimates(users: Array<User>) {
let estimateGroups: { [key: number]: string[] } = {};
let estimateGroups: { [key: number | string]: string[] } = {};
users.forEach((user) => {
if (user.estimate !== null) {
if (estimateGroups[user.estimate]) {
@@ -109,10 +99,8 @@ wss.on('connection', (ws: WebSocket, req) => {
const allEstimates = room.getAllEstimates();
if (allEstimates.size === room.getUsers().length) {
const users = room.getUsers();
const average = calculateAverageEstimate(users);
broadcastToRoom(room.id, {
type: 'estimation-closed',
average,
groupedEstimates: groupEstimates(users)
});
}