-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.js
53 lines (42 loc) · 1.3 KB
/
testing.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
var mysql = require('promise-mysql');
var express = require('express');
var app = express();
/*
Load the RedditAPI class and create an API with db connection. This connection will stay open as
long as the web server is running, which is 24/7.
*/
var RedditAPI = require('./lib/reddit.js');
var connection = mysql.createPool({
user: 'root',
database: 'reddit'
});
var myReddit = new RedditAPI(connection);
/* test function for user login */
// myReddit.checkUserLogin('HotSatin', 'abc123')
// .then(function(user) {
// console.log(user);
// })
// .catch(function(err) {
// console.log(err);
// })
/* test function for creating a user session */
myReddit.createUserSession('newname')
// myReddit.getSubredditByName('1')
// .then(function(name) {
// console.log(name);
// })
// .catch(function(err) {
// console.log(err);
// });
app.get('/sort/:method', function(request, response){
myReddit.getAllPosts().then(function(sortPosts){
if(request.params.method === myReddit.getAllPosts.hot) {
response.render('post-list', {posts: sortPosts})
} else if (request.params.method === myReddit.getAllPosts.top) {
response.render('post-list',{posts: sortPosts})
} else{
response.status(404).send('404 Not Found');
}
response.send('post-list');
})
});