-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (54 loc) · 1.61 KB
/
index.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
const { Pool } = require('pg');
const pool = new Pool({
user: "postgres",
host: require('./config.json').ip,
database: "manage_invite_six",
password: "",
port: 5432
});
const open = require('open');
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
app.get('/', async (req, res) => {
const { rows: results } = await pool.query(`
with data as (
select
date_trunc('day', created_at) as day,
count(1)
from payments WHERE type = 'paypal_dash_pmnt_month'
group by 1
)
select
to_char(day,'DD-MM') as day,
sum(count) over (order by day asc rows between unbounded preceding and current row)
from data
`);
res.render('stats.ejs', {
labels: results.map((e) => e.day),
values: results.map((e) => req.query.money ? e.sum * 1.5 : e.sum)
});
});
app.get('/by-day', async (req, res) => {
const { rows: results } = await pool.query(`
with data as (
select
date_trunc('day', created_at) as day,
count(1)
from payments WHERE type = 'paypal_dash_pmnt_month'
group by 1
)
select day, to_char(day,'DD-MM') as d, sum(count)
from data
group by 1
order by 1
DESC
`);
res.render('by-day.ejs', {
labels: results.reverse().map((e) => e.d),
values: results.map((e) => req.query.money ? e.sum * 1.5 : e.sum)
});
});
app.listen(8080);
open('http://localhost:8080')
console.log('8080 is the magic port');