-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
29 lines (25 loc) · 945 Bytes
/
routes.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
// imports
var persistenceService = require('./persistence.js');
// static class definition
var routes = {
getTweets: function (req, res) {
Promise.all([persistenceService.getTweets(), persistenceService.getTopics()]).then(function (data) {
var tweets = data[0].filter((v)=> v.hashtags.indexOf(req.params.topic) > -1);
var topic = data[1].filter((v)=> v.hashtags.indexOf(req.params.topic) > -1)[0];
res.send({
tweets: tweets,
text: topic.text,
creation_date: topic.creation_date
});
})
},
getTopics: function (req, res) {
persistenceService.getTopics().then(function (topics) {
topics = topics.map((v)=> v.hashtags.filter((v) => v != 'pixel_dailies'));
topics = topics.filter((v)=>v && v.length > 0);
res.send(topics);
})
}
};
// export
module.exports = routes;