1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { healthData } from "https://esm.town/v/nate/healthData";
import { isAuthenticated } from "https://esm.town/v/nate/isAuthenticated";
export let recordHealthData = (params) => {
if (isAuthenticated(params)) {
const date = params["date"];
// Expected input is a string with the number of heartbeats for each
// minute of the day, filled in with 0s. This converts it to a hash of
// the minute of the day to the number of heartbeats, excluding minutes
// with no data.
const heartRate = {};
params["heartRate"]
.split("\r\n")
.map((item: string) => +(item || "").trim())
.forEach((item: number, index: number) => {
if (item > 0) heartRate[index] = item;
});
const steps = parseInt(params["steps"]);
healthData.heartRate[date] = heartRate;
healthData.steps[date] = steps;
return true;
} else {
return false;
}
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.