-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
89 lines (79 loc) · 2.8 KB
/
sample.js
File metadata and controls
89 lines (79 loc) · 2.8 KB
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
require('dotenv').config();
process.env.NTBA_FIX_319 = 1;
const axios = require('axios').default;
const moment = require('moment');
const FlightMonitorAlertBot = require('./bot/flightMonitorAlertBot');
var flightMonitorAlertBot = new FlightMonitorAlertBot();
async function VerificarVoosLatam (listParams) {
let baseUrl = 'https://bff.latam.com/ws/proxy/booking-webapp-bff/v1/public/revenue/recommendations/oneway';
if (!listParams.length) {
return;
}
var promises = [];
var listaRotas = listParams.map(x => `- ${x.origin}/${x.destination} no dia ${moment(x.departure).format('DD/MM/YYYY')}`).join('\n');
var listaVoosSemEscala = [];
flightMonitorAlertBot.sendMessage(`- Iniciando verificacao de voos sem escalas a venda para as seguintes rotas:\n\n${listaRotas}`);
listParams.forEach(params => {
promises.push(new Promise((resolve, reject) => {
axios.get(baseUrl, { params: params }).then(response => {
let voos = response.data.data[0].flights;
let voosSemEscalas = voos.filter(x => x.stops < 1);
if (voosSemEscalas.length > 0) {
listaVoosSemEscala = listaVoosSemEscala.concat(voosSemEscalas);
}
resolve();
});
}));
});
Promise.all(promises).then(() => {
if (listaVoosSemEscala.length > 0) {
flightMonitorAlertBot.sendMessage(`${listaVoosSemEscala.length} voos sem escala encontrados:\n\n${listaVoosSemEscala.map(voo => `- ( Voo ${voo.flightCode} ) ( ${voo.stops} Escalas ) - Partida de ${voo.departure.airportCode} as ${voo.departure.time.stamp} / Chegada em ${voo.arrival.airportCode} as ${voo.arrival.time.stamp}`).join('\n')}`);
}
setTimeout(() => {
flightMonitorAlertBot.sendMessage('Finalizando verificacao de voos sem escalas a venda');
}, 1000);
});
}
var listParams = [
{
"departure": "2020-07-02",
"origin": "FOR",
"destination": "MCZ",
"cabin": "Y",
"country": "BR",
"language": "PT",
"home": "pt_br",
"adult": "1"
},
{
"departure": "2020-07-02",
"origin": "FOR",
"destination": "AJU",
"cabin": "Y",
"country": "BR",
"language": "PT",
"home": "pt_br",
"adult": "1"
},
{
"departure": "2020-05-05",
"origin": "FOR",
"destination": "CNF",
"cabin": "Y",
"country": "BR",
"language": "PT",
"home": "pt_br",
"adult": "1"
},
{
"departure": "2020-04-04",
"origin": "FOR",
"destination": "VIX",
"cabin": "Y",
"country": "BR",
"language": "PT",
"home": "pt_br",
"adult": "1"
},
];
VerificarVoosLatam(listParams);