-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
73 lines (62 loc) · 1.96 KB
/
server.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
64
65
66
67
68
69
70
71
72
73
const express = require('express');
const morgan = require('morgan');
const dotenv = require('dotenv').config();
const async = require('async');
const request = require('request');
const _ = require('lodash');
const utils = require("./helpers/parseEvents");
const app = express();
app.use(morgan('dev'));
app.get('/taxonomies', function(req, res) {
const seatgeekUrl = process.env.SEATGEEK_TAXONOMIES_URL;
request.get({
'url': seatgeekUrl,
'json': true,
}, function(err, response, body){
taxonomies = utils.getTaxonomies(body.taxonomies);
res.json({ taxonomies });
});
});
app.get('/events', function(req, res){
let seatgeekUrl = process.env.SEATGEEK_EVENT_URL;
let ticketmasterUrl = process.env.TICKETMASTER_URL;
seatgeekUrl += "&aid=12614";
seatgeekUrl += "&per_page=3000";
seatgeekUrl += "&sort=datetime_utc.asc";
seatgeekUrl += "&lowest_price.gte=10";
seatgeekUrl += "&average_price.lte=1000";
seatgeekUrl += "&taxonomies.name=" + utils.mapCategory(req.query.category);
seatgeekUrl += "&postal_code=" + req.query.zipCode;
console.log(seatgeekUrl);
let data;
async.parallel([
function(callback) {
request.get({
'url': seatgeekUrl,
'json': true,
}, function(err, response, body){
if(err) return callback(err);
data = utils.parseToMessenger(utils.parseSeatGeek(body.events));
callback();
});
},
function(callback) {
request.get({
'url': ticketmasterUrl,
'json': true,
}, function(err, response, body) {
if(err) return callback(err);
// utils.parseTicketMaster(body._embedded.events, req);
// data.push({"ticketmaster": body._embedded.events});
callback();
})
}
], function(err) {
//function gets called after apis are being called
if(err) { console.log(err); };
res.json(data);
});
});
var port = process.env.PORT || 8000;
app.listen(port);
console.log("App listening on port " + port);