-
Notifications
You must be signed in to change notification settings - Fork 0
/
Results.js
85 lines (70 loc) · 1.54 KB
/
Results.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Read tests from db and send them back to the application
* this script is not ready!
*/
const mysql = require('mysql');
const url = require('url');
const config = require(__dirname + "/config.json");
class Results {
constructor(req) {
this.conn = mysql.createConnection(config.dbCredentials);
this.conn.connect(function(err) {
if (err) {
console.log("Database must be online");
throw err;
}
console.log("MySQL Connected!");
});
this.filter = {};
var urlObject = url.parse(req.url,true);
var params = urlObject.query;
this.setFilter('cycle', '1');
this.setFilter('ok', 0);
console.dir(params);
console.dir(this.getFilter());
let ret = {
browsers : this.getBrowsers(),
}
console.dir(ret);
return ret;
};
setFilter(key, value) {
this.filter[key] = value;
}
setFilters(obj) {
for(var key in obj) {
if(obj[key] == "") {
continue;
}
this.filter[key] = obj[key];
}
};
getFilter() {
let ret = [];
for(var key in this.filter) {
//ret.push("`" + key + "` = '${this.filter[key]}'")
}
return ret.join(' AND ');
};
getFailedTests(filter) {
let sql = "SELECT * FROM ";
};
getBrowsers() {
let sql = 'SELECT browser FROM results ';
let filter = this.getFilter();
if(filter != "") {
sql += "WHERE " + filter;
}
sql += ' GROUP BY browser ';
this.conn.query({
sql: sql,
}, (error, res, fields) => {
if (error) {
throw error;
}
return res.map((item, index) => { return item.browser; });
});
return false;
};
};
exports.Results = Results;