-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (43 loc) · 1.34 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 express = require('express');
const Pool = require('pg').Pool;
const moe = express();
const port = process.env.PORT || 5000
const { query } = require('./moe');
const pool = new Pool({
user: process.env.USER,
host: process.env.HOST,
database: process.env.DATABASE,
password: process.env.PASSWORD,
port: 5432,
});
const adminkey = ["Moe1234"];
moe.get('/', (req, res) => res.send('Hi'))
moe.get('/jail', (req, res)=> {
const lockup = req.query.lockup
pool.query('SELECT user_id, reason FROM gbans WHERE user_id=$1', [lockup])
.then(result => res.send(result.rows))
.catch(error => console.log(error))
});
moe.get('/ban', (req, res)=> {
const userid = req.query.userid
const name = req.query.name
const reason = req.query.reason
const apikey = req.query.apikey
if(adminkey.includes(apikey)) {
pool.query('INSERT INTO gbans(user_id, name, reason) VALUES ($1, $2, $3)', [userid, name, reason])
.then(result => res.send(result.rows))
.catch(error => console.log(error))
}
});
moe.get('/unban', (req, res)=> {
const userid = req.query.userid
const apikey = req.query.apikey
if(adminkey.includes(apikey)) {
pool.query('DELETE FROM gbans WHERE user_id=($1)', [userid])
.then(result => res.send(result.rows))
.catch(error => console.log(error))
}
})
moe.listen( port, () => {
console.log(`Connected to port ${port}`)
} )