forked from maratonusp/contestwatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
49 lines (41 loc) · 943 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
const logger = require('./logger');
const lowdb = require('lowdb');
const low = lowdb('db.json', {
storage: require('lowdb/lib/storages/file-async')
});
module.exports = {low: low};
module.exports.user = (function () {
var User = {};
low.defaults({users: []}).write();
User.create = function (id) {
logger.info('Creating user ' + id);
low.get('users')
.push({
id: id,
notify: false,
ignore: {calendar: true},
last_activity: Date.now(),
cf_handles: [],
})
.write();
return low
.get('users')
.find({id : id});
}
User.get = function (id) {
var user = low
.get('users')
.find({id : id});
if (user.isUndefined().value())
return module.exports.user.create(id);
return user;
}
User.migrate = function (old_id, new_id) {
logger.info('Migrating user ' + old_id + ' to ' + new_id);
var user = User
.get(old_id)
.assign({id : new_id})
.write();
}
return User;
})();