feat: nextjs setup and configuration (lib, store, css, assets)
This commit is contained in:
1 parent
eff6c00a9c
commit
c5a1b8e5d2
17 files changed
+1933
-17
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import api from './api';
|
||||
import { CartItem } from '../store/cartStore';
|
||||
|
||||
export interface OrderItem {
|
||||
id: string;
|
||||
orderId: string;
|
||||
productId: string | null;
|
||||
quantity: number;
|
||||
product?: any;
|
||||
}
|
||||
|
||||
export interface Order {
|
||||
id: string;
|
||||
userId: string;
|
||||
couponId: string | null;
|
||||
totalAmount: number;
|
||||
charityDonation: number;
|
||||
status: string;
|
||||
trackingNumber: string | null;
|
||||
createdAt: string;
|
||||
orderItems: OrderItem[];
|
||||
}
|
||||
|
||||
export class OrderService {
|
||||
private static instance: OrderService;
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): OrderService {
|
||||
if (!OrderService.instance) {
|
||||
OrderService.instance = new OrderService();
|
||||
}
|
||||
return OrderService.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new order on the backend
|
||||
*/
|
||||
public async createOrder(orderData: {
|
||||
petId?: string;
|
||||
items: { productId: string; quantity: number }[];
|
||||
}): Promise<Order> {
|
||||
try {
|
||||
const response = await api.post('/orders', orderData);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const message = error.response?.data?.message || 'خطا در ثبت سفارش';
|
||||
throw new Error(Array.isArray(message) ? message[0] : message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all orders for the current user
|
||||
*/
|
||||
public async getUserOrders(): Promise<Order[]> {
|
||||
try {
|
||||
const response = await api.get('/orders');
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const message = error.response?.data?.message || 'خطا در دریافت لیست سفارشها';
|
||||
throw new Error(Array.isArray(message) ? message[0] : message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order details by ID
|
||||
*/
|
||||
public async getOrderById(id: string): Promise<Order> {
|
||||
try {
|
||||
const response = await api.get(`/orders/${id}`);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const message = error.response?.data?.message || 'خطا در دریافت جزئیات سفارش';
|
||||
throw new Error(Array.isArray(message) ? message[0] : message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const orderService = OrderService.getInstance();
|
||||
Reference in new issue
Block a user