This commit is contained in:
g
2025-02-07 21:33:13 +00:00
parent 8900bbcc76
commit 891f57d729
50 changed files with 165 additions and 444 deletions

View File

@@ -1,13 +1,11 @@
import { fetchData } from '@/lib/data-service';
export const fetchProductData = async (url: string, authToken: string) => {
try {
const response = await fetch(url, {
return await fetchData(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;
@@ -21,7 +19,7 @@ export const saveProductData = async (
method: "POST" | "PUT" = "POST"
) => {
try {
const response = await fetch(url, {
return await fetchData(url, {
method,
headers: {
Authorization: `Bearer ${authToken}`,
@@ -30,10 +28,6 @@ export const saveProductData = async (
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;
@@ -42,7 +36,7 @@ export const saveProductData = async (
export const deleteProductData = async (url: string, authToken: string) => {
try {
const response = await fetch(url, {
return await fetchData(url, {
method: "DELETE",
headers: {
Authorization: `Bearer ${authToken}`,
@@ -50,13 +44,8 @@ export const deleteProductData = async (url: string, authToken: string) => {
},
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;
}
};
};