-
Notifications
You must be signed in to change notification settings - Fork 0
/
duration.js
44 lines (37 loc) · 954 Bytes
/
duration.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const supabase = require("./supabase");
const userDurations = new Map();
function startDuration(userId) {
// Record the start time
userDurations.set(userId, {
startTime: new Date(),
endTime: null,
totalDuration: 0,
});
}
function endDuration(durationInfo) {
durationInfo.endTime = new Date();
durationInfo.totalDuration = Math.floor(
(durationInfo.endTime.getTime() - durationInfo.startTime.getTime()) / 1000
);
}
async function saveDuration(dsUId, dsGlobalName, dsTag, start, end, duration) {
// Save the duration to the Superbase database
try {
const { data, error, status } = await supabase
.from("user")
.insert({ dsUId, dsGlobalName, dsTag, start, end, duration });
if (error) {
console.log(error);
} else {
console.log(data, status);
}
} catch (err) {
console.log(err);
}
}
module.exports = {
startDuration,
endDuration,
saveDuration,
userDurations,
};