42 } as ApiResponse<Cart>);
43 } catch (error) {
44 console.error("Error fetching cart:", error);
45 return c.json({
46 success: false,
47 error: "Failed to fetch cart"
48 } as ApiResponse<null>, 500);
49 }
28 } as ApiResponse<Product[]>);
29 } catch (error) {
30 console.error("Error fetching products:", error);
31 return c.json({
32 success: false,
33 error: "Failed to fetch products"
34 } as ApiResponse<null>, 500);
35 }
62 } as ApiResponse<Product>);
63 } catch (error) {
64 console.error("Error fetching product:", error);
65 return c.json({
66 success: false,
67 error: "Failed to fetch product"
68 } as ApiResponse<null>, 500);
69 }
80 } as ApiResponse<ProductCategory[]>);
81 } catch (error) {
82 console.error("Error fetching categories:", error);
83 return c.json({
84 success: false,
85 error: "Failed to fetch categories"
86 } as ApiResponse<null>, 500);
87 }
211 formData.append('image', selectedFile);
212
213 const response = await fetch('/api/remove-background', {
214 method: 'POST',
215 body: formData
50
51 // Call the Remove.bg API
52 const response = await fetch("https://api.remove.bg/v1.0/removebg", {
53 method: "POST",
54 headers: {
93});
94
95export default app.fetch;
120
121// This is the entry point for HTTP vals
122export default app.fetch;
41 const token = localStorage.getItem("token");
42 if (token) {
43 fetchCurrentUser(token);
44 } else {
45 setLoading(false);
47 }, []);
48
49 const fetchCurrentUser = async (token: string) => {
50 try {
51 const response = await fetch("/api/auth/me", {
52 headers: {
53 "Authorization": `Bearer ${token}`
64 }
65 } catch (error) {
66 console.error("Error fetching user:", error);
67 localStorage.removeItem("token");
68 } finally {
45
46// This is the entry point for HTTP vals
47export default app.fetch;
21 useEffect(() => {
22 if (currentUser) {
23 // Direct fetch for products
24 fetch(`${API_BASE_URL}/products`, {
25 headers: {"Accept": "application/json", "X-User-Id": currentUser.id} // X-User-Id might not be strictly needed
26 })
28 if (!res.ok) {
29 const errorData = await res.json().catch(() => ({message: `HTTP error ${res.status}`}))
30 throw new Error(errorData.message || `Failed to fetch products: ${res.status}`)
31 }
32 return res.json()
33 })
34 .then(setProducts)
35 .catch(err => setError(err.message || "Failed to fetch products for reconciliation."))
36 }
37 }, [currentUser])
53 setSuccessMessage(null)
54 try {
55 // Direct fetch for reconcileInventory
56 const response = await fetch(`${API_BASE_URL}/inventory/reconcile`, {
57 method: "POST",
58 headers: {
104 })
105
106 const detectResponse = await fetch(`${API_BASE_URL}/images/detect-products`, {
107 method: "POST",
108 headers: {
135 if (foundProduct) {
136 try {
137 const reconcileResponse = await fetch(`${API_BASE_URL}/inventory/reconcile`, {
138 method: "POST",
139 headers: {"Content-Type": "application/json", "Accept": "application/json", "X-User-Id": currentUser.id},
22
23 try {
24 const response = await fetch("/api/auth/login", {
25 method: "POST",
26 headers: {
76 };
77
78 // Fetch notifications when user is logged in
79 useEffect(() => {
80 if (!user || !token) return;
81
82 const fetchNotifications = async () => {
83 try {
84 const response = await fetch('/api/notifications', {
85 headers: {
86 'Authorization': `Bearer ${token}`,
95 }
96
97 const countResponse = await fetch('/api/notifications/unread-count', {
98 headers: {
99 'Authorization': `Bearer ${token}`,
108 }
109 } catch (error) {
110 console.error('Failed to fetch notifications:', error);
111 }
112 };
113
114 fetchNotifications();
115
116 // Set up SSE for real-time updates
146
147 try {
148 const response = await fetch('/api/notifications/read-all', {
149 method: 'PUT',
150 headers: {