-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
51 lines (39 loc) · 926 Bytes
/
db.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
let openDoor = false;
let entries = [];
let lockTimer;
exports.shouldOpenDoor = () => {
return new Promise(accept => accept(openDoor));
};
exports.allowDoor = () => {
clearLockTimer();
return new Promise(accept => {
openDoor = true;
// start timer to disallow door in 5 minutes
lockTimer = setTimeout(() => {
this.disallowDoor();
}, 1000 * 60 * 5);
accept();
});
};
exports.disallowDoor = () => {
clearLockTimer();
return new Promise(accept => {
openDoor = false;
accept();
});
};
exports.recordAllowedEntry = () => {
entries.push({ action: "ALLOWED", time: Date.now() });
};
exports.recordDisallowedEntry = () => {
entries.push({ action: "DISALLOWED", time: Date.now() });
};
exports.getEntries = () => {
return new Promise(accept => accept(entries));
};
function clearLockTimer() {
if (lockTimer) {
clearTimeout(lockTimer);
lockTimer = null;
}
}