restructured - added data and inventory routes/controllers

This commit is contained in:
2024-03-21 13:35:47 -05:00
parent 31939aaffe
commit ab2b011580
5 changed files with 19 additions and 19 deletions

View File

@@ -0,0 +1,34 @@
import fetch from "node-fetch";
import fetchEbayToken from "../utils/fetchEbayToken.js"; // Adjust the import path according to your project structure
export const itemLookup = async (req, res) => {
const productCode = req.query.productCode;
const oauthToken = await fetchEbayToken();
console.log(productCode);
try {
const response = await fetch(
`https://api.ebay.com/buy/browse/v1/item_summary/search?gtin=${productCode}`,
{
method: "GET",
headers: {
Authorization: `Bearer ${oauthToken}`,
"Content-Type": "application/json",
},
}
);
console.log(response);
if (!response.ok)
throw new Error("Failed to fetch data from eBay Browse API");
const data = await response.json();
const price = [];
data.itemSummaries.forEach((item) => {
price.push(item.price, item.condition);
});
res.status(200).send(price);
} catch (error) {
console.error("Error fetching data from eBay Browse API:", error);
res.status(500).send("Internal Server Error");
}
};