-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
90 lines (80 loc) · 2.47 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var express = require('express');
const app = express();
const path = require('path');
var bodyParser= require('body-parser');
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.get('/', (req, res) => {
res.render('index')
})
app.use(bodyParser.urlencoded({ extended: true}))
// #############
// Client
// #############
app.post('/submit', (req, res) => {
console.log(req.body)
const origin = req.body.origin
const destination = req.body.destination
const date = req.body.date
// res.redirect('/')
})
app.listen(3000, () => {
console.log(`App running at http://localhost:3000`)
})
// #############
// API
// #############
// var unirest = require("unirest");
// var connDeets = require('./connDeets');
// var req = unirest("GET", "https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/USD/en-US/CUN-sky/MIA-sky/2019-01-12");
// req.headers({
// "x-rapidapi-host": connDeets.host,
// "x-rapidapi-key": connDeets.api_key
// });
//
// req.query({
// "inboundpartialdate": "2019-01-12"
// });
//
// req.end(function (res) {
// // console.log(res)
// if (res.error) {
// console.log("One or more fields are invalid. Please check input and try again.");
// process.exit(1)
// }
//
// var queryMap = new Map ();
//
// for (quote in res.body["Quotes"]) {
// var price = res.body["Quotes"][quote]["MinPrice"]
// console.log("Price to travel to MIA -> CUN ");
// // console.log(price);
// }
//
// // GOAL: grab price of flight
// var price = res.body["Quotes"][0]["MinPrice"]
// // ---------------------
//
// // GOAL: direct flight?
// var isDirect = res.body["Quotes"][0]["Direct"]
// // ---------------------
//
// // GOAL: change number of id to name of flight company
// // traverse carrierIds for outbound flights
// var idToCarr;
// for (var id in res.body["Quotes"][0]["OutboundLeg"]["CarrierIds"]) {
// // traverse all known carriers
// for (var key in res.body["Carriers"]) {
// // check if the carrierIds match the carriers provided and if so change their
// if (res.body["Quotes"][0]["OutboundLeg"]["CarrierIds"][id] == res.body["Carriers"][key]["CarrierId"]) {
// res.body["Quotes"][0]["OutboundLeg"]["CarrierIds"][id] = res.body["Carriers"][key]["Name"]
// idToCarr = res.body["Quotes"][0]["OutboundLeg"]["CarrierIds"][id];
// }
// }
// }
//
// queryMap.set(price, idToCarr)
// for (var [key, value] of queryMap) {
// // console.log(key + ' : ' + value);
// }
// });