-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-utils.js
38 lines (28 loc) · 1.37 KB
/
fetch-utils.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
import fetch from "node-fetch";
export const fetchListOfStores = async (lat, long) => {
const storeListUrl = `https://www.tacobell.com/tacobellwebservices/v4/tacobell/stores?latitude=${lat}&longitude=${long}`;
const res = await fetch(storeListUrl);
const data = await res.json();
let formattedList = [];
if(data.nearByStores.length > 0) {
const storeData = data.nearByStores.length > 10 ? data.nearByStores.slice(0, 10) : data.nearByStores;
for (const location of storeData) {
formattedList.push({
name: `${location.storeNumber} - ${location.address.line1} ${location.address.town}, ${location.address.region.isocode.substring(3)}`,
value: location.storeNumber
});
}
return formattedList;
} else {
return formattedList;
}
}
export const fetchBurrito = async (storeNumber) => {
const storeProductsUrl = `https://www.tacobell.com/tacobellwebservices/v4/tacobell/products/menu/${storeNumber}`;
const res = await fetch(storeProductsUrl);
const data = await res.json();
const menuCategories = data.menuProductCategories;
const burritos = menuCategories.find(item => item.name === "Burritos");
const fiveLayerBurrito = burritos.products.find(burrito => burrito.name === "Beefy 5-Layer Burrito");
return fiveLayerBurrito.price.formattedValue;
}