-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
200 lines (178 loc) · 5.15 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var express = require("express");
var bodyParser = require('body-parser');
var events = require("events");
var rest = require("./rest");
var eventEmitter = new events.EventEmitter();
var fs = require('fs');
var form = fs.readFileSync('./web/form.html');
var qs = require('querystring');
var app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var formValue = {};
var sharedContext = {};
var response;
var bargainFinderMaxActivity = function() {
console.log("BargainFinderMax");
formValue.departureDateTime = formValue.departureDate+"T00:00:00";
var requestObject = {
event : "bfm",
nextEvent : "end",
service : "/v1.8.6/shop/flights?mode=live",
query : {
"OTA_AirLowFareSearchRQ": {
"OriginDestinationInformation": [
{
"DepartureDateTime": formValue.departureDate+"T00:00:00",
"DestinationLocation": {
"LocationCode": formValue.destination
},
"OriginLocation": {
"LocationCode": formValue.origin
},
"RPH":"1"
}
],
"POS": {
"Source": [
{
"RequestorID": {
"CompanyName": {
"Code": "TN"
},
"ID": "REQ.ID",
"Type": "0.AAA.X"
}
}
]
},
"TPA_Extensions": {
"IntelliSellTransaction": {
"RequestType": {
"Name": "50ITINS"
}
}
},
"TravelerInfoSummary": {
"AirTravelerAvail": [
{
"PassengerTypeQuantity": [
{
"Code": "ADT",
"Quantity": 1
}
]
}
]
}
}
}
,
directUrl : null
};
rest.post(requestObject, sharedContext, eventEmitter);
}
var instaFlightActivity = function() {
console.log("InstaFlight");
var requestObject = {
event: "if",
nextEvent: "bfm",
service: "",
directUrl: sharedContext["lpc"].FareInfo[0].Links[0].href
};
rest.get(requestObject, sharedContext, eventEmitter);
}
var leadPriceCalendarActivity = function() {
console.log("LeadPriceCalendar");
var requestObject = {
event : "lpc",
nextEvent : "if",
service : "/v2/shop/flights/fares",
query : formValue,
directUrl : null
};
rest.get(requestObject, sharedContext, eventEmitter);
}
var AutoCompleteActivity = function() {
console.log("AutoCompleteActivity");
var requestObject = {
event : "ac",
nextEvent : "acend",
service : "/v1/lists/utilities/geoservices/autocomplete",
query : formValue,
directUrl : null
};
rest.get(requestObject, sharedContext, eventEmitter);
}
var AutoCompleteEnd = function() {
var prettyResult = {
re: {
OriginLocation: sharedContext
}
};
if(prettyResult.re.OriginLocation.ac.Response !== undefined && prettyResult.re.OriginLocation.ac.Response.grouped !== undefined){
//console.log(JSON.stringify(prettyResult.re.OriginLocation.ac));
response.end(JSON.stringify(prettyResult.re.OriginLocation.ac.Response.grouped["category:AIR"].doclist.docs));
}
}
var workflowEnd = function() {
var prettyResult = {
lpc: {
OriginLocation: sharedContext.lpc.OriginLocation,
DestinationLocation: sharedContext.lpc.DestinationLocation,
FareInfo: sharedContext.lpc.FareInfo[0]
},
"if": {
FirstItinerary: sharedContext['if'].PricedItineraries[0].AirItinerary.OriginDestinationOptions.OriginDestinationOption[0]
},
bfm: {
FirstItinerary: sharedContext.bfm //.OTA_AirLowFareSearchRS.PricedItineraries.PricedItinerary[0]
}
};
//console.log(JSON.stringify(prettyResult));
response.end(JSON.stringify(prettyResult));
}
eventEmitter.on("lpc", leadPriceCalendarActivity);
eventEmitter.on("if", instaFlightActivity);
eventEmitter.on("bfm", bargainFinderMaxActivity);
eventEmitter.on("end", workflowEnd);
eventEmitter.on("ac", AutoCompleteActivity);
eventEmitter.on("acend", AutoCompleteEnd);
app.use(express.static('web'));
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
app.post('/AutoCompleteCity', urlencodedParser, function(req, res) {
//console.log(req.query.q);
formValue = {
query: req.query.q,
category: "AIR",
limit: 30
}
eventEmitter.emit("ac");
console.log("Autocompelete");
response = res;
});
app.post('/fs', urlencodedParser, function(req, res) {
console.log(req.body.destination);
formValue = {
origin: req.body.origin,
destination: req.body.destination,
departureDate: req.body.departureDate,
lengthofstay: 5
}
eventEmitter.emit("lpc");
console.log("Post END");
response = res;
});
app.listen(1337, function () {});