forked from SabreDevStudio/bargain-finder-max-sample-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bfm_model.js
116 lines (108 loc) · 2.79 KB
/
bfm_model.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
const request = require('request-promise-native');
const FileHelper = require('./file_helper');
class BargainFinderMaxModel {
constructor(params) {
Object.assign(this, params);
}
get itineraries() {
return this.response;
}
async readRequest() {
try {
const response = await request({
method: 'POST',
url: `${this.apiEndPoint}/v4.2.0/shop/flights?mode=live`,
headers: {
'content-type': 'application/json',
authorization: `Bearer ${this.apiAccessToken}`,
},
body: this.toBodyString(),
});
FileHelper.writeData(response, '../mocks/bfm.json');
this.response = JSON.parse(response);
return this.response;
} catch (error) {
console.log(`Flight Search response error ${error.statusCode}`);
console.log(JSON.parse(error.error));
return -1;
}
}
toBodyString() {
const requestPayload = {
OTA_AirLowFareSearchRQ: {
DirectFlightsOnly: false,
AvailableFlightsOnly: true,
Version: '4.1.0',
POS: {
Source: [
{
PseudoCityCode: this.pcc,
RequestorID: {
Type: '1',
ID: '1',
CompanyName: {
Code: 'TN',
content: 'TN',
},
},
},
],
},
OriginDestinationInformation: [
{
RPH: '1',
DepartureDateTime: this.timeStampLeave,
OriginLocation: {
LocationCode: this.fromAirportCode,
},
DestinationLocation: {
LocationCode: this.toAirportCode,
},
},
{
RPH: '2',
DepartureDateTime: this.timeStampReturn,
OriginLocation: {
LocationCode: this.toAirportCode,
},
DestinationLocation: {
LocationCode: this.fromAirportCode,
},
},
],
TravelPreferences: {
ValidInterlineTicket: true,
},
TravelerInfoSummary: {
SeatsRequested: [
1,
],
AirTravelerAvail: [
{
PassengerTypeQuantity: [
{
Code: 'ADT',
Quantity: 1,
TPA_Extensions: {
VoluntaryChanges: {
Match: 'Info',
},
},
},
],
},
],
},
TPA_Extensions: {
IntelliSellTransaction: {
RequestType: {
Name: '50ITINS',
},
},
},
},
};
return JSON.stringify(requestPayload);
}
}
module.exports = BargainFinderMaxModel;