-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.js
More file actions
52 lines (42 loc) · 1.76 KB
/
route.js
File metadata and controls
52 lines (42 loc) · 1.76 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
const path = require('path');
const moment = require('moment');
const DBService = require('./services/DBService')
const TwitterService = require('./services/TwitterService');
const BlogService = require('./services/BlogService');
const { exit } = require('process');
module.exports = function (app) {
app.get('/', (req, res) => {
res.render('welcome')
})
//process tweet, convert as blog and save to DB
app.get('/blogit/:username', async function(req, res){
const username = req.params.username
const resUser = await TwitterService.reqUserData(username)
if (resUser == undefined) {
res.send({'success': false, 'msg': 'username not found'})
}
DBService.saveUser(resUser)
BlogService.processTweetToBlog(resUser['id']).then(function(){
res.send({ 'success': true, 'username': username })
})
});
app.get('/blog/:username', async function(req, res){
const user = await DBService.getUser(req.params.username)
const _authorId = user.id
DBService.getBlogs(_authorId).then(function (blogs) {
res.render('blog', { blogs: blogs, moment: moment, user: user })
})
})
app.get('/blog/show/:slug', async function(req, res){
const blog = await DBService.getBlog(req.params.slug)
res.render('show', { blog: blog, moment: moment })
})
app.get('/blog/update/:userId', async function(req, res){
const latestBlog = await DBService.getLatestBlogByUser(req.params.userId)
BlogService.processTweetToBlog(latestBlog[0].author_id, latestBlog[0].id)
.then(function (blogs) {
//blogs is here if needed
res.send({'status': 'OKAY'})
})
})
}