diff --git a/src/models/timer.js b/src/models/timer.js index 8afbad119..09c2f89da 100644 --- a/src/models/timer.js +++ b/src/models/timer.js @@ -8,6 +8,7 @@ const timerSchema = new Schema({ startAt: { type: Date, default: Date.now }, time: { type: Number, default: 900000 }, goal: { type: Number, default: 900000 }, + initialGoal: { type: Number, default: 900000 }, paused: { type: Boolean, default: false }, forcedPause: { type: Boolean, default: false }, started: { type: Boolean, default: false }, diff --git a/src/websockets/TimerService/clientsHandler.js b/src/websockets/TimerService/clientsHandler.js index e9e932fd7..3bb2c358d 100644 --- a/src/websockets/TimerService/clientsHandler.js +++ b/src/websockets/TimerService/clientsHandler.js @@ -81,32 +81,30 @@ const ackForcedPause = (client) => { }; const stopTimer = (client) => { + if (client.started) pauseTimer(client); client.startAt = moment.invalid(); client.started = false; client.pause = false; client.forcedPause = false; + if (client.time === 0) { + client.goal = client.initialGoal; + client.time = client.goal; + } else { + client.goal = client.time; + } }; const clearTimer = (client) => { stopTimer(client); + client.goal = client.initialGoal; client.time = client.goal; }; const setGoal = (client, msg) => { const newGoal = parseInt(msg.split('=')[1]); - if (!client.started) { - client.goal = newGoal; - client.time = newGoal; - } else { - const passedTime = client.goal - client.time; - if (passedTime >= newGoal) { - client.time = 0; - client.goal = passedTime; - } else { - client.time = newGoal - passedTime; - client.goal = newGoal; - } - } + client.goal = newGoal; + client.time = newGoal; + client.initialGoal = newGoal; }; const addGoal = (client, msg) => {