Spaces:
Running
Running
import { apiRequest } from "./queryClient"; | |
const API_BASE = ""; | |
// Auth API | |
export const authApi = { | |
register: (data: any) => apiRequest("POST", `${API_BASE}/api/auth/register`, data), | |
login: (data: any) => apiRequest("POST", `${API_BASE}/api/auth/login`, data), | |
sellerLogin: (data: any) => apiRequest("POST", `${API_BASE}/api/auth/seller-login`, data), | |
}; | |
// Categories API | |
export const categoriesApi = { | |
getAll: () => fetch(`${API_BASE}/api/categories`).then(res => res.json()), | |
create: (data: any) => apiRequest("POST", `${API_BASE}/api/categories`, data), | |
update: (id: string, data: any) => apiRequest("PUT", `${API_BASE}/api/categories/${id}`, data), | |
delete: (id: string) => apiRequest("DELETE", `${API_BASE}/api/categories/${id}`), | |
}; | |
// Products API | |
export const productsApi = { | |
getAll: (params?: any) => { | |
const searchParams = new URLSearchParams(params); | |
return fetch(`${API_BASE}/api/products?${searchParams}`).then(res => res.json()); | |
}, | |
getFeatured: () => fetch(`${API_BASE}/api/products/featured`).then(res => res.json()), | |
getById: (id: string) => fetch(`${API_BASE}/api/products/${id}`).then(res => res.json()), | |
create: (formData: FormData) => apiRequest("POST", `${API_BASE}/api/products`, formData), | |
update: (id: string, formData: FormData) => apiRequest("PUT", `${API_BASE}/api/products/${id}`, formData), | |
delete: (id: string) => apiRequest("DELETE", `${API_BASE}/api/products/${id}`), | |
}; | |
// Stores API | |
export const storesApi = { | |
getAll: () => fetch(`${API_BASE}/api/stores`).then(res => res.json()), | |
getById: (id: string) => fetch(`${API_BASE}/api/stores/${id}`).then(res => res.json()), | |
create: (formData: FormData) => apiRequest("POST", `${API_BASE}/api/stores`, formData), | |
update: (id: string, formData: FormData) => apiRequest("PUT", `${API_BASE}/api/stores/${id}`, formData), | |
}; | |
// Cart API | |
export const cartApi = { | |
get: () => apiRequest("GET", `${API_BASE}/api/cart`), | |
add: (data: any) => apiRequest("POST", `${API_BASE}/api/cart`, data), | |
update: (id: string, data: any) => apiRequest("PUT", `${API_BASE}/api/cart/${id}`, data), | |
remove: (id: string) => apiRequest("DELETE", `${API_BASE}/api/cart/${id}`), | |
}; | |
// Orders API | |
export const ordersApi = { | |
get: () => apiRequest("GET", `${API_BASE}/api/orders`), | |
create: (data: any) => apiRequest("POST", `${API_BASE}/api/orders`, data), | |
}; | |
// User API | |
export const userApi = { | |
getProfile: () => apiRequest("GET", `${API_BASE}/api/user/profile`), | |
updateProfile: (data: any) => apiRequest("PUT", `${API_BASE}/api/user/profile`, data), | |
}; | |
// Admin API | |
export const adminApi = { | |
getSellers: () => fetch(`${API_BASE}/api/admin/sellers`).then(res => res.json()), | |
createSeller: (data: any) => apiRequest("POST", `${API_BASE}/api/admin/sellers`, data), | |
deleteSeller: (id: string) => apiRequest("DELETE", `${API_BASE}/api/admin/sellers/${id}`), | |
deleteProduct: (id: string) => apiRequest("DELETE", `${API_BASE}/api/admin/products/${id}`), | |
updateProduct: (id: string, data: any) => apiRequest("PUT", `${API_BASE}/api/admin/products/${id}`, data), | |
getOrders: () => fetch(`${API_BASE}/api/admin/orders`).then(res => res.json()), | |
updateOrder: (id: string, data: any) => apiRequest("PATCH", `${API_BASE}/api/admin/orders/${id}`, data), | |
}; | |
// Seller API | |
export const sellerApi = { | |
getStore: () => apiRequest("GET", `${API_BASE}/api/seller/store`), | |
getProducts: () => apiRequest("GET", `${API_BASE}/api/seller/products`), | |
getOrders: () => apiRequest("GET", `${API_BASE}/api/seller/orders`), | |
updateOrder: (id: string, data: any) => apiRequest("PATCH", `${API_BASE}/api/seller/orders/${id}`, data), | |
}; | |