Change schema and switch to flask-sqlalchemy, comment out existing endpoints and add new endpoints to add/delete users & workouts

This commit is contained in:
Peter Stockings
2023-03-08 20:32:54 +11:00
parent f7805609b0
commit ec2e848f48
3 changed files with 235 additions and 57 deletions

View File

@@ -63,6 +63,7 @@
let isRunning = false;
let startTime = 0;
let intervalId = null;
let workout = [];
const integerNumber = (num) => parseInt(num);
const decimalNumber = (num) => parseFloat(num.toFixed(1));
@@ -105,6 +106,20 @@
clearInterval(intervalId);
toggleButton.textContent = 'Start';
disconnect();
fetch("/user/1/workouts", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ workout: workout }),
}).then(res => res.json())
.then(res => swal("Submitted", json.stringify(res), "success"))
.catch(err => swal("Failed to submit workout", err.message, "error"));
workout = [];
}
// Toggle workout
@@ -200,8 +215,10 @@
characteristic.addEventListener("characteristicvaluechanged", props.onChange);
console.log("> Characteristic value changed event listener added");
/*
btn.classList.remove("bg-blue-600");
btn.classList.add("bg-green-600");
*/
}
async function disconnect() {
@@ -213,8 +230,10 @@
"characteristicvaluechanged",
handleNotifications
);
/*
btn.classList.remove("bg-green-600");
btn.classList.add("bg-blue-600");
*/
} catch (error) {
console.log("Argh! " + error);
swal("Oops", error, "error");
@@ -261,6 +280,8 @@
updateRpmPower(rpm, 0);
updateGraph();
workout.push({ rpm, timestamp: new Date() })
/*
fetch("/cadence", {
method: "POST",