Spaces:
Running
Running
File size: 3,643 Bytes
b89a86e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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),
};
|