This repository was archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
105 lines (82 loc) · 2.03 KB
/
index.js
File metadata and controls
105 lines (82 loc) · 2.03 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var express = require('express');
var app = express();
var knex = require('./connection');
var request = require('request');
//CORS
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods',
'GET, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization');
next();
});
app.get('/all', function(req, res, next) {
knex('logging.changesets').select()
.then(function(result){
res.send(result);
})
.catch(function (err) {
console.log(err);
next(err);
});
});
app.get('/leaders', function(req, res, next) {
knex.select(
'username',
'uid',
knex.raw('SUM(num_changes) as changes'),
knex.raw('array_agg(tag) as tags'),
knex.raw('array_agg(changeset_id) as changesets'),
knex.raw('array_agg(closed_at) as dates')
)
.from('logging.changesets')
.groupByRaw('username, uid')
.orderByRaw('changes DESC')
.then(function(result){
res.send(result);
})
.catch(function (err) {
console.log(err);
next(err);
});
});
app.get('/total', function(req, res, next) {
knex.select(
knex.raw('SUM(num_changes) as total')
)
.from('logging.changesets')
.then(function(result){
res.send(result[0]);
})
.catch(function (err) {
console.log(err);
next(err);
});
});
app.get('/roads', function(req, res, next) {
knex.select('value')
.from('logging.stats')
.where({key: 'totalRoads'})
.then(function(result){
res.send(result[0]);
})
.catch(function (err) {
console.log(err);
next(err);
});
});
app.get('/roadswithstartdate', function(req, res, next) {
knex.select('value')
.from('logging.stats')
.where({key: 'taggedRoads'})
.then(function(result){
res.send(result[0]);
})
.catch(function (err) {
console.log(err);
next(err);
});
});
app.listen(3030);