-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouteShape.js
More file actions
executable file
·64 lines (63 loc) · 1.46 KB
/
routeShape.js
File metadata and controls
executable file
·64 lines (63 loc) · 1.46 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
#!/usr/bin/env node
const fetch = require("node-fetch")
const data = require("./data/simpleOrder.json")
const { decodeCoordinates } = require('./utils/flexiblePolyline')
const endpoint = process.env.ENDPOINT || "https://dev.backend.impargo.eu/"
const TOKEN = process.env.TOKEN
const query = `
mutation importOrder($data: OrderImportInput!){
importOrder(data:$data) {
_id
order {
reference
route {
distance
time
routeDetails {
legs {
calculatedRoute {
segments {
name
type
distance
time
encodedCoordinates
}
}
}
}
}
}
}
}
`
fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"authorization": TOKEN
},
body: JSON.stringify({
query: query,
variables: {
data,
},
})
})
.then(result => {
return result.json();
})
.then(result => {
if (result.errors) {
console.error(result.errors)
}
console.log("Order successfully created");
let coordinates = []
result.data.importOrder.order.route.routeDetails?.legs.forEach(leg => {
leg.calculatedRoute.segments.forEach(segment => {
coordinates = coordinates.concat(decodeCoordinates(segment.encodedCoordinates))
})
})
console.log('decoded coordinates: ', coordinates.length)
console.log(coordinates)
});