-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequestFactory.js
58 lines (53 loc) · 1.78 KB
/
RequestFactory.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
class RequestBodyFactory {
static createRequestBody({ fromIATA, toIATA, departureDay, returnDay, transfers }) {
const dateDeparture = new Date(departureDay).toLocaleDateString('en-GB').split('/').reverse().join('-');
const dateReturn = returnDay && new Date(returnDay).toLocaleDateString('en-GB').split('/').reverse().join('-');
const innerRequestBody = [
[],
[null, null, 2, null, [], 1, [1, 0, 0, 0], null, null, null, null, null, null, [
[
[
[
[fromIATA, 0]
]
],
[
[
[toIATA, 0]
]
], null,
Number(transfers), // 0 - any number of stops, 1 - direct flights, 2 - 1 stop, 3 - 2 stops
[],
[], dateDeparture, null, [],
[],
[], null, null, [], 3
],
...(dateReturn ?
[[
[
[
[toIATA, 0]
]
],
[
[
[fromIATA, 0]
]
], null,
Number(transfers),
[],
[], dateReturn, null, [],
[],
[], null, null, [], 3
]] : [])
], null, null, null, 1, null, null, null, null, null, []], 1, 0, 0
];
const b = [
null,
JSON.stringify(innerRequestBody),
];
// console.debug(JSON.stringify(b));
return `f.req=${encodeURIComponent(JSON.stringify(b))}`;
}
}
module.exports = { RequestBodyFactory };