-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdestinyPool.js
48 lines (44 loc) · 1.51 KB
/
destinyPool.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
'use strict';
const poolDB = require('./db.js');
class DestinyPool {
constructor(channelID, newPool) {
this.channelID = channelID;
}
setPool(pool) {
var channelID = this.channelID;
return new Promise((resolve, reject) => {
poolDB.query("delete from channel where id = $1::text", [channelID], function(err, res) {
if(err) {
console.error('error running query', err);
reject(err);
}
poolDB.query("insert into channel (id, config) values ($1::text, $2::text);", [channelID, JSON.stringify(pool)], function(err, res) {
if(err) {
console.error('error running query', err);
reject(err);
}
resolve(true);
});
});
});
}
getPool() {
var channelID = this.channelID;
return new Promise((resolve, reject) => {
poolDB.query("select * from channel where id = $1::text", [channelID], function(err, res) {
var pool;
if(err) {
console.error('error running query', err);
reject(err);
}
if (res && res.rows[0]){
pool = JSON.parse(res.rows[0].config);
} else {
pool = [];
}
resolve(pool);
});
});
}
};
module.exports = DestinyPool;