|
|
@ -54,7 +54,8 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
...activeData(w.id), |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -76,6 +77,11 @@ module.exports = function workoutRouter(repo) { |
|
|
|
if (measurements == null) { |
|
|
|
return res.status(404).json({code: 404, message: "measurements not found"}) |
|
|
|
} |
|
|
|
|
|
|
|
for (const measurement of measurements) { |
|
|
|
delete measurement.id; |
|
|
|
delete measurement.workoutId; |
|
|
|
} |
|
|
|
|
|
|
|
return res.status(200).json(measurements); |
|
|
|
} catch (err) { |
|
|
@ -95,6 +101,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
@ -102,6 +109,31 @@ module.exports = function workoutRouter(repo) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
router.put("/:id", async(req, res) => { |
|
|
|
let workout = workouts.find(w => w.id == req.params.id); |
|
|
|
if (workout == null) { |
|
|
|
return res.status(404).json({code: 404, message: "Workout not found or inactive."}) |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
if (req.body.cooldownMin) { |
|
|
|
workout.setCooldownMin(req.body.cooldownMin); |
|
|
|
await repo.updateWorkout(workout) |
|
|
|
} |
|
|
|
|
|
|
|
return res.status(200).json({ |
|
|
|
id: workout.id, |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
|
return res.status(400).json({code: 400, message: err.message || err}) |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
router.post("/:id/continue", async(req, res) => { |
|
|
|
let workout = workouts.find(w => w.id == req.params.id); |
|
|
|
if (workout != null) { |
|
|
@ -117,7 +149,8 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
...activeData(w.id), |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
|
return res.status(400).json({code: 400, message: err.message || err}) |
|
|
@ -137,6 +170,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch(err) { |
|
|
@ -157,6 +191,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch(err) { |
|
|
@ -177,6 +212,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch(err) { |
|
|
@ -203,6 +239,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch(err) { |
|
|
@ -229,6 +266,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
...activeData(workout.id), |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
@ -267,10 +305,15 @@ module.exports = function workoutRouter(repo) { |
|
|
|
} |
|
|
|
workout.events.on("state", onState); |
|
|
|
|
|
|
|
const onCooldownMin = (cooldownMin) => { |
|
|
|
ws.send(JSON.stringify({cooldownMin})) |
|
|
|
} |
|
|
|
workout.events.on("cooldownMin", onCooldownMin); |
|
|
|
|
|
|
|
ws.onclose = () => { |
|
|
|
workout.events.removeListener("workoutStatus", onWorkoutStatus); |
|
|
|
workout.events.removeListener("state", onState); |
|
|
|
workout.events.removeListener("cooldownMin", onCooldownMin); |
|
|
|
ws.removeAllListeners(); |
|
|
|
}; |
|
|
|
|
|
|
@ -281,6 +324,7 @@ module.exports = function workoutRouter(repo) { |
|
|
|
bike: workout.bike, |
|
|
|
program: workout.program, |
|
|
|
date: workout.date, |
|
|
|
cooldownMin: workout.cooldownMin, |
|
|
|
}, |
|
|
|
})); |
|
|
|
}) |
|
|
|