Skip to content

Commit 49ca057

Browse files
committed
Fun update
1 parent 358512a commit 49ca057

File tree

8 files changed

+547
-1146
lines changed

8 files changed

+547
-1146
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/app/.vite
2+
src/app/app.functions/node_modules
3+
src/app/app.functions/package-lock.json
4+
src/app/app.functions/.env
5+
src/app/extensions/node_modules
6+
src/app/extensions/package-lock.json

advanced_version/RentalCars/src/app/app.functions/getLocations.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ function calculateDistance(a, b) {
55
const earthRadiusMiles = 3958.8; // Average radius of the Earth in miles
66

77
// Convert degrees to radians
8-
const lat1 = a.lat * (Math.PI/180);
9-
const lng1 = a.lng * (Math.PI/180);
10-
const lat2 = b.lat * (Math.PI/180);
11-
const lng2 = b.lng * (Math.PI/180);
8+
const lat1 = a.lat * (Math.PI / 180);
9+
const lng1 = a.lng * (Math.PI / 180);
10+
const lat2 = b.lat * (Math.PI / 180);
11+
const lng2 = b.lng * (Math.PI / 180);
1212

1313
// Haversine formula
1414
const differenceLat = lat2 - lat1;
1515
const differenceLng = lng2 - lng1;
1616
const aHav = Math.pow(Math.sin(differenceLat / 2), 2) +
17-
Math.cos(lat1) * Math.cos(lat2) *
18-
Math.pow(Math.sin(differenceLng / 2), 2);
17+
Math.cos(lat1) * Math.cos(lat2) *
18+
Math.pow(Math.sin(differenceLng / 2), 2);
1919
const c = 2 * Math.atan2(Math.sqrt(aHav), Math.sqrt(1 - aHav));
2020

2121
// Distance in miles
@@ -57,9 +57,10 @@ function fetchLocations({ lat_min, lat_max, lng_min, lng_max, pickupDate, return
5757
number_of_available_vehicles
5858
hs_object_id
5959
associations {
60-
p_vehicles_collection__vehicles_to_locations {
60+
all_vehicles: p_vehicles_collection__vehicles_to_locations {
6161
items {
6262
hs_object_id
63+
model
6364
}
6465
total
6566
}
@@ -70,10 +71,10 @@ function fetchLocations({ lat_min, lat_max, lng_min, lng_max, pickupDate, return
7071
}
7172
}`,
7273
variables: {
73-
"lat_min":lat_min,
74-
"lat_max":lat_max,
75-
"lng_min":lng_min,
76-
"lng_max":lng_max,
74+
"lat_min": lat_min,
75+
"lat_max": lat_max,
76+
"lng_min": lng_min,
77+
"lng_max": lng_max,
7778
"pickupDate": pickupDate,
7879
"returnDate": returnDate,
7980
"vehicleClass": vehicleClass
@@ -85,7 +86,7 @@ function fetchLocations({ lat_min, lat_max, lng_min, lng_max, pickupDate, return
8586
url: 'https://api.hubapi.com/collector/graphql',
8687
headers: {
8788
'Content-Type': 'application/json',
88-
'Authorization': 'Bearer '+process.env['PRIVATE_APP_ACCESS_TOKEN'],
89+
'Authorization': 'Bearer ' + process.env['PRIVATE_APP_ACCESS_TOKEN'],
8990
},
9091
data: data,
9192
maxBodyLength: Infinity

advanced_version/RentalCars/src/app/app.functions/getVehicles.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ const axios = require('axios');
33

44
exports.main = async (context, sendResponse) => {
55

6-
let vehicleIds = context.parameters.vehicles;
6+
let vehicleIds = context.parameters.vehicles;
77

8-
let data = JSON.stringify({
9-
"inputs": vehicleIds.map((id) => {
10-
return {
11-
"id": id
12-
}
13-
}),
14-
"properties": [
15-
"vin",
16-
"make",
17-
"model",
18-
"year",
19-
"daily_price"
20-
]
21-
});
8+
let data = JSON.stringify({
9+
"inputs": vehicleIds.map((id) => {
10+
return {
11+
"id": id
12+
}
13+
}),
14+
"properties": [
15+
"vin",
16+
"make",
17+
"model",
18+
"year",
19+
"daily_price"
20+
]
21+
});
2222

23-
let config = {
24-
method: 'post',
25-
maxBodyLength: Infinity,
26-
url: 'https://api.hubapi.com/crm/v3/objects/vehicles/batch/read',
27-
headers: {
28-
'Authorization': 'Bearer '+process.env['PRIVATE_APP_ACCESS_TOKEN'],
29-
'Content-Type': 'application/json'
30-
},
31-
data : data
32-
};
23+
let config = {
24+
method: 'post',
25+
maxBodyLength: Infinity,
26+
url: 'https://api.hubapi.com/crm/v3/objects/vehicles/batch/read',
27+
headers: {
28+
'Authorization': 'Bearer ' + process.env['PRIVATE_APP_ACCESS_TOKEN'],
29+
'Content-Type': 'application/json'
30+
},
31+
data: data
32+
};
3333

34-
axios.request(config)
35-
.then((response) => {
36-
console.log(JSON.stringify(response.data));
37-
sendResponse({data: response.data});
38-
})
39-
.catch((error) => {
40-
console.log(error);
41-
throw error;
42-
});
34+
return axios.request(config)
35+
.then((response) => {
36+
console.log(JSON.stringify(response.data));
37+
return response.data
38+
})
39+
.catch((error) => {
40+
console.log(error);
41+
throw error;
42+
});
4343
}

0 commit comments

Comments
 (0)