-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (75 loc) · 2.13 KB
/
index.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
const axios = require("axios");
const qs = require("qs");
class FedexService {
fetchOrderID(nrIdentificao, nrDocumento) {
return new Promise((resolve, reject) => {
const data = {
remDest: "D",
nrIdentificacao: nrIdentificao,
idFilial: "",
tpDocumento: "NF",
nrDocumento: nrDocumento,
};
const BASE_URL_ID =
"https://radar.tntbrasil.com.br/radar/public/localizacaoSimplificada/search";
axios({
method: "post",
url: BASE_URL_ID,
data: qs.stringify(data),
headers: {
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
},
})
.then((response) => {
console.log(response);
if (response.data.aaData.length > 0) {
const orderID = response.data.aaData[0];
resolve(orderID.id)
} else {
reject('Credenciais invalidas')
}
})
.catch((error) => reject(error));
});
}
fetchDocumentID(orderID) {
return new Promise((resolve, reject) => {
axios
.get(
`https://radar.tntbrasil.com.br/radar/public/localizacaoSimplificadaDetail/${orderID}`
)
.then((response) => {
const html = response.data;
let index = html.indexOf("idDocumento");
let idDocumento = [];
while (html[index] != ",") {
idDocumento.push(html[index]);
index++;
}
idDocumento = idDocumento.join("");
let initialPosition = idDocumento.indexOf(":");
let finalPosition = idDocumento.length;
idDocumento = idDocumento.substring(initialPosition + 2, finalPosition);
resolve(idDocumento)
})
.catch((error) => {
reject(error)
});
})
}
actualStatusOrder(id) {
return new Promise((resolve, reject) => {
axios
.get(
`https://radar.tntbrasil.com.br/radar/service/tracking/findLinhaTempoEvento?idDoctoServico=${id}`
)
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
}
module.exports = FedexService;