slight cleanup

This commit is contained in:
g
2025-02-07 19:30:49 +00:00
parent 40635ae667
commit 8900bbcc76
11 changed files with 438 additions and 477 deletions

31
lib/data-service.ts Normal file
View File

@@ -0,0 +1,31 @@
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' })
};