Skip to content

Commit b3657aa

Browse files
authored
Add no inventory message for Ford (#136)
1 parent d10af42 commit b3657aa

File tree

1 file changed

+105
-96
lines changed

1 file changed

+105
-96
lines changed

app/src/manufacturers/ford.js

Lines changed: 105 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,34 @@ import { apiRequest } from "../helpers/request";
1919
import {
2020
convertToCurrency,
2121
generateErrorMessage,
22+
generateInfoMessage,
2223
normalizeJson,
2324
sortObjectByKey,
2425
titleCase,
2526
} from "../helpers/libs";
26-
import { fordInventoryMapping, fordVinMapping } from "./fordMappings";
27+
import { fordVinMapping } from "./fordMappings";
2728

29+
// eslint-disable-next-line
2830
export async function getFordInventory(zip, year, model, radius, manufacturer) {
29-
try {
30-
const invResponse = await apiRequest(
31-
"inventory",
32-
manufacturer,
33-
[...arguments],
34-
[],
35-
45000,
36-
);
37-
return formatFordInventoryResults(invResponse, year);
38-
} catch (error) {
39-
throw generateErrorMessage(error);
40-
}
31+
return generateInfoMessage(
32+
"Inventory Not Available",
33+
`Inventory information for the ${year} Ford ${titleCase(
34+
model,
35+
)} is not available at this time.<br><br>Please visit <a href="https://www.ford.com/finder/2024/f150-lightning" target="_blank">https://shop.ford.com</a> for more detail.`,
36+
);
37+
38+
// try {
39+
// const invResponse = await apiRequest(
40+
// "inventory",
41+
// manufacturer,
42+
// [...arguments],
43+
// [],
44+
// 45000,
45+
// );
46+
// return formatFordInventoryResults(invResponse, year);
47+
// } catch (error) {
48+
// throw generateErrorMessage(error);
49+
// }
4150
}
4251

4352
export async function getFordVinDetail(
@@ -69,89 +78,89 @@ export async function getFordVinDetail(
6978
}
7079
}
7180

72-
function formatFordInventoryResults(input, year) {
73-
if (Object.keys(input.data.filterResults).length == 0) {
74-
// filterResults is empty when no vehicles are found for a given search
75-
// Returning an empty object so the UI displays the no vehicles found message
76-
return {};
77-
}
78-
79-
let vehicles = input.data.filterResults.ExactMatch.vehicles;
80-
let d =
81-
input.data.filterSet.filterGroupsMap.Dealer[0].filterItemsMetadata.filterItems;
82-
83-
// rdata is returned from the EV Finder API when it has to page to retrieve all available
84-
// inventory information for a given search. Here we're merging the initial inventory
85-
// results with any paginated inventory results
86-
if (Object.hasOwn(input, "rdata")) {
87-
Object.keys(input.rdata).forEach((key) => {
88-
if (key == "vehicles") {
89-
// Merging vehicle information
90-
input.rdata[key].forEach((vehiclePaginationResult) => {
91-
vehicles = vehicles.concat(vehiclePaginationResult);
92-
});
93-
} else {
94-
// Merging dealer information
95-
input.rdata[key].forEach((dealerPaginationResult) => {
96-
d = d.concat(dealerPaginationResult);
97-
});
98-
}
99-
});
100-
}
101-
102-
var n = normalizeJson(vehicles, fordInventoryMapping);
103-
/**
104-
* Loop through the dealer information in the returned inventory object,
105-
* and pull out the dealerId and dealer name. We'll use this hashmap to
106-
* populate information displayed in the UI
107-
*/
108-
const dealers = {};
109-
110-
d.forEach((dealer) => {
111-
dealers[dealer["value"]] = {
112-
// 'value' is the key for the dealer ID
113-
displayName: dealer["displayName"],
114-
distance: dealer["distance"],
115-
};
116-
});
117-
118-
n.forEach((vehicle) => {
119-
// The dealerSlug is needed for VIN detail calls. Storing here for use later
120-
vehicle["dealerSlug"] = input["dealerSlug"];
121-
122-
// Format the inventory status
123-
vehicle["daysOnDealerLot"] > 0
124-
? ((vehicle["deliveryDate"] = `In Stock for ${vehicle["daysOnDealerLot"]} days`),
125-
(vehicle["inventoryStatus"] = "In Stock"))
126-
: ((vehicle["deliveryDate"] = "Unknown"),
127-
(vehicle["inventoryStatus"] = "In Stock"));
128-
129-
/**
130-
* In testing, I've seen where the dealerId provided in an individual
131-
* vehicle response, doesn't match any dealerId provided by the inventory
132-
* API response (API error?). So catching that and falling back to deriving
133-
* the dealer's name from another field.
134-
*/
135-
const dealerId = vehicle["dealerPaCode"];
136-
try {
137-
vehicle["distance"] = dealers[dealerId]["distance"];
138-
vehicle["dealerName"] = dealers[dealerId]["displayName"];
139-
} catch (error) {
140-
// /dealer/Santa-Monica-Ford-12345/model/2022-Mache/ -> Santa Monica Ford 12345
141-
vehicle["dealerName"] = vehicle["detailPageUrl"]
142-
.split("/")[2]
143-
.replaceAll("-", " ");
144-
vehicle["distance"] = "0";
145-
}
146-
});
147-
148-
/**
149-
* If no vehicles are found for a given model year the Ford API will return inventory
150-
* for the current model year. After receiving the API response we need to filter it
151-
* so we only return results for the requested model year
152-
*/
153-
return n.filter((vehicle) => vehicle.year == year);
154-
}
81+
// function formatFordInventoryResults(input, year) {
82+
// if (Object.keys(input.data.filterResults).length == 0) {
83+
// // filterResults is empty when no vehicles are found for a given search
84+
// // Returning an empty object so the UI displays the no vehicles found message
85+
// return {};
86+
// }
87+
88+
// let vehicles = input.data.filterResults.ExactMatch.vehicles;
89+
// let d =
90+
// input.data.filterSet.filterGroupsMap.Dealer[0].filterItemsMetadata.filterItems;
91+
92+
// // rdata is returned from the EV Finder API when it has to page to retrieve all available
93+
// // inventory information for a given search. Here we're merging the initial inventory
94+
// // results with any paginated inventory results
95+
// if (Object.hasOwn(input, "rdata")) {
96+
// Object.keys(input.rdata).forEach((key) => {
97+
// if (key == "vehicles") {
98+
// // Merging vehicle information
99+
// input.rdata[key].forEach((vehiclePaginationResult) => {
100+
// vehicles = vehicles.concat(vehiclePaginationResult);
101+
// });
102+
// } else {
103+
// // Merging dealer information
104+
// input.rdata[key].forEach((dealerPaginationResult) => {
105+
// d = d.concat(dealerPaginationResult);
106+
// });
107+
// }
108+
// });
109+
// }
110+
111+
// var n = normalizeJson(vehicles, fordInventoryMapping);
112+
// /**
113+
// * Loop through the dealer information in the returned inventory object,
114+
// * and pull out the dealerId and dealer name. We'll use this hashmap to
115+
// * populate information displayed in the UI
116+
// */
117+
// const dealers = {};
118+
119+
// d.forEach((dealer) => {
120+
// dealers[dealer["value"]] = {
121+
// // 'value' is the key for the dealer ID
122+
// displayName: dealer["displayName"],
123+
// distance: dealer["distance"],
124+
// };
125+
// });
126+
127+
// n.forEach((vehicle) => {
128+
// // The dealerSlug is needed for VIN detail calls. Storing here for use later
129+
// vehicle["dealerSlug"] = input["dealerSlug"];
130+
131+
// // Format the inventory status
132+
// vehicle["daysOnDealerLot"] > 0
133+
// ? ((vehicle["deliveryDate"] = `In Stock for ${vehicle["daysOnDealerLot"]} days`),
134+
// (vehicle["inventoryStatus"] = "In Stock"))
135+
// : ((vehicle["deliveryDate"] = "Unknown"),
136+
// (vehicle["inventoryStatus"] = "In Stock"));
137+
138+
// /**
139+
// * In testing, I've seen where the dealerId provided in an individual
140+
// * vehicle response, doesn't match any dealerId provided by the inventory
141+
// * API response (API error?). So catching that and falling back to deriving
142+
// * the dealer's name from another field.
143+
// */
144+
// const dealerId = vehicle["dealerPaCode"];
145+
// try {
146+
// vehicle["distance"] = dealers[dealerId]["distance"];
147+
// vehicle["dealerName"] = dealers[dealerId]["displayName"];
148+
// } catch (error) {
149+
// // /dealer/Santa-Monica-Ford-12345/model/2022-Mache/ -> Santa Monica Ford 12345
150+
// vehicle["dealerName"] = vehicle["detailPageUrl"]
151+
// .split("/")[2]
152+
// .replaceAll("-", " ");
153+
// vehicle["distance"] = "0";
154+
// }
155+
// });
156+
157+
// /**
158+
// * If no vehicles are found for a given model year the Ford API will return inventory
159+
// * for the current model year. After receiving the API response we need to filter it
160+
// * so we only return results for the requested model year
161+
// */
162+
// return n.filter((vehicle) => vehicle.year == year);
163+
// }
155164

156165
function formatFordVinResults(input) {
157166
const v = normalizeJson([input.data.selected], fordVinMapping)[0];

0 commit comments

Comments
 (0)