96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import { Order } from '../../entities/commerce/order';
|
|
import { Product, ProductCategory } from '../../entities/commerce/product';
|
|
import { BaseEntity, MoneyAmount } from '../../entities/types';
|
|
import { IRepository } from './repository';
|
|
|
|
export interface PriceList extends BaseEntity {
|
|
name: string;
|
|
code: string;
|
|
currency: string;
|
|
isDefault: boolean;
|
|
status: 'active' | 'archived';
|
|
prices: Record<string, MoneyAmount>; // productId -> MoneyAmount
|
|
}
|
|
|
|
export interface Payment extends BaseEntity {
|
|
orderId: string;
|
|
orderNumber: string;
|
|
amount: MoneyAmount;
|
|
method: 'card' | 'cash' | 'online' | 'bank_transfer';
|
|
status: 'completed' | 'pending' | 'failed' | 'refunded';
|
|
transactionId?: string;
|
|
idempotencyKey?: string;
|
|
paidAt: string;
|
|
recipientAccount?: string;
|
|
}
|
|
|
|
export interface ShipmentItem {
|
|
productId: string;
|
|
sku: string;
|
|
name: string;
|
|
quantity: number;
|
|
}
|
|
|
|
export interface Shipment extends BaseEntity {
|
|
orderId: string;
|
|
orderNumber: string;
|
|
warehouseId: string;
|
|
status: 'draft' | 'ready' | 'shipped' | 'delivered';
|
|
trackingNumber?: string;
|
|
carrier?: string;
|
|
dispatchedAt?: string;
|
|
deliveredAt?: string;
|
|
items: ShipmentItem[];
|
|
}
|
|
|
|
export interface ReturnItem {
|
|
productId: string;
|
|
sku: string;
|
|
name: string;
|
|
quantity: number;
|
|
refundAmount: MoneyAmount;
|
|
}
|
|
|
|
export interface Return extends BaseEntity {
|
|
orderId: string;
|
|
orderNumber: string;
|
|
status: 'requested' | 'approved' | 'received' | 'refunded' | 'rejected';
|
|
totalRefund: MoneyAmount;
|
|
reason: string;
|
|
items: ReturnItem[];
|
|
}
|
|
|
|
export interface ICommerceService {
|
|
products: IRepository<Product>;
|
|
categories: IRepository<ProductCategory>;
|
|
priceLists: IRepository<PriceList>;
|
|
orders: IRepository<Order>;
|
|
payments: IRepository<Payment>;
|
|
shipments: IRepository<Shipment>;
|
|
returns: IRepository<Return>;
|
|
updateOrderStatus(orderId: string, status: Order['status']): Promise<Order>;
|
|
confirmOrder(orderId: string, warehouseId?: string): Promise<Order>;
|
|
cancelOrder(orderId: string): Promise<Order>;
|
|
createPayment(
|
|
orderId: string,
|
|
amount: MoneyAmount,
|
|
method: Payment['method'],
|
|
autoRecordFinance?: boolean,
|
|
idempotencyKey?: string
|
|
): Promise<Payment>;
|
|
createShipment(orderId: string, warehouseId: string, items?: ShipmentItem[]): Promise<Shipment>;
|
|
createReturn(
|
|
orderId: string,
|
|
reason: string,
|
|
items: ReturnItem[],
|
|
warehouseId?: string,
|
|
autoRecordFinance?: boolean
|
|
): Promise<Return>;
|
|
processReturn(
|
|
orderId: string,
|
|
reason: string,
|
|
items: ReturnItem[],
|
|
warehouseId?: string,
|
|
autoRecordFinance?: boolean
|
|
): Promise<Return>;
|
|
}
|