balls
This commit is contained in:
62
lib/productData.ts
Normal file
62
lib/productData.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export const fetchProductData = async (url: string, authToken: string) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
credentials: "include",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch product data");
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error fetching product data:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const saveProductData = async (
|
||||
url: string,
|
||||
data: any,
|
||||
authToken: string,
|
||||
method: "POST" | "PUT" = "POST"
|
||||
) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to save product data");
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error saving product data:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteProductData = async (url: string, authToken: string) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to delete product data");
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error deleting product data:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user