31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { fetchClient } from './client-utils';
|
|
import type { Product, ShippingMethod, ApiResponse } from './types';
|
|
|
|
export const ProductService = {
|
|
getAll: async (): Promise<ApiResponse<Product[]>> =>
|
|
fetchClient('/products'),
|
|
|
|
create: async (product: Omit<Product, '_id'>): Promise<ApiResponse<Product>> =>
|
|
fetchClient('/products', { method: 'POST', body: JSON.stringify(product) }),
|
|
|
|
update: async (id: string, product: Partial<Product>): Promise<ApiResponse<Product>> =>
|
|
fetchClient(`/products/${id}`, { method: 'PUT', body: JSON.stringify(product) }),
|
|
|
|
delete: async (id: string): Promise<ApiResponse<void>> =>
|
|
fetchClient(`/products/${id}`, { method: 'DELETE' })
|
|
};
|
|
|
|
// Shipping Operations
|
|
export const ShippingService = {
|
|
getAll: async (): Promise<ApiResponse<ShippingMethod[]>> =>
|
|
fetchClient('/shipping-options'),
|
|
|
|
create: async (method: Omit<ShippingMethod, '_id'>): Promise<ApiResponse<ShippingMethod>> =>
|
|
fetchClient('/shipping-options', { method: 'POST', body: JSON.stringify(method) }),
|
|
|
|
update: async (id: string, method: Partial<ShippingMethod>): Promise<ApiResponse<ShippingMethod>> =>
|
|
fetchClient(`/shipping-options/${id}`, { method: 'PUT', body: JSON.stringify(method) }),
|
|
|
|
delete: async (id: string): Promise<ApiResponse<void>> =>
|
|
fetchClient(`/shipping-options/${id}`, { method: 'DELETE' })
|
|
}; |