-
Notifications
You must be signed in to change notification settings - Fork 0
/
follows.js
63 lines (48 loc) · 1.71 KB
/
follows.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
var con = require('./connection')
var express = require('express');
var router = express.Router();
router.get('/api/follows', async (req, res) => {
con.getConnection(res, (response) => {
if (response.message == 'fail') return;
response.conn.query("SELECT * FROM follows", function (err, result, fields) {
res.send(JSON.stringify(result));
});
});
});
router.get('/api/followedByID', async (req, res) => {
con.getConnection(res, (response) => {
if (response.message == 'fail') return;
response.conn.query(`SELECT * FROM follows where followed = ${req.body.followed}`,
function (err, result, fields) {
res.send(JSON.stringify(result));
});
});
});
router.get('/api/followerByID', async (req, res) => {
con.getConnection(res, (response) => {
if (response.message == 'fail') return;
response.conn.query(`SELECT * FROM follows where follower = ${req.body.follower}`,
function (err, result, fields) {
res.send(JSON.stringify(result));
});
});
});
router.delete('/api/follows', async (req, res) => {
con.getConnection(res, (response) => {
if (response.message == 'fail') return;
response.conn.query(`delete from follows where follower = ${req.body.follower} AND
followed = ${req.body.followed}`,function (err, result, fields) {
res.send(JSON.stringify(result));
});
});
});
router.post('/api/follows',async (req, res) => {
con.getConnection(res, (response) => {
if (response.message == 'fail') return;
response.conn.query(`INSERT INTO follows (follower,followed) VALUES
(${req.body.follower},${req.body.followed});`,function (err, result, fields) {
res.send(JSON.stringify(result));
});
});
});
module.exports = router;