feat(#1): Add estimate option for not choosing a number

This commit is contained in:
Josh Creek
2023-07-13 19:59:23 +00:00
parent 7def4c21a8
commit d7900644c4
7 changed files with 10 additions and 34 deletions
+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)
});
}