slight cleanup
This commit is contained in:
31
lib/data-service.ts
Normal file
31
lib/data-service.ts
Normal 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' })
|
||||
};
|
||||
Reference in New Issue
Block a user