-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifs.js
67 lines (58 loc) · 1.29 KB
/
notifs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var deasync = require("deasync");
var db = require("./db");
// Wait for a promise without using the await
function wait(promise) {
var done = 0;
var result = null;
promise.then(
// on value
function(value) {
done = 1;
result = value;
return value;
},
// on exception
function(reason) {
done = 1;
throw reason;
}
);
while (!done) deasync.runLoopOnce();
return result;
}
const UserDetails = () => {
const obj = wait(db.userinfo.find({}));
return obj;
};
const ExercisesQuery = query => {
return wait(db.exercises.find(query));
};
const getUserDetails = () => {
return UserDetails()[0].data;
};
var User = getUserDetails();
const getUserPosture = space => {
if (space.startsWith("Small")) {
return "stand";
} else {
return "lay";
}
};
module.exports = {
getNormalPlan: () => {
let plans = ExercisesQuery({
orien: getUserPosture(User.roomspc),
prof: User.prof.toLowerCase()
});
return plans[Math.floor(Math.random() * plans.length)];
},
getPosturePlans: () => {
if (User.orientation === "sit") {
let plans = ExercisesQuery({
orien: getUserPosture(User.roomspc),
prof: User.prof.toLowerCase()
});
return plans[Math.floor(Math.random() * plans.length)];
}
}
};