feat(F-106): completed feature
This commit is contained in:
@@ -5,7 +5,7 @@ import type {
|
||||
OrderServicePort,
|
||||
CreateOrderCommand,
|
||||
} from '../domain/ports.js';
|
||||
import { isTransitionAllowed, type OrderState, type OrderView } from '../domain/order.js';
|
||||
import { isTransitionAllowed, type OrderState, type OrderView, type OrderItemInput } from '../domain/order.js';
|
||||
|
||||
export class OrderService implements OrderServicePort {
|
||||
constructor(
|
||||
@@ -39,6 +39,20 @@ export class OrderService implements OrderServicePort {
|
||||
return this.repo.search(filters);
|
||||
}
|
||||
|
||||
/** Edición admin: reemplaza artículos y totales del pedido. */
|
||||
async editItems(
|
||||
id: string,
|
||||
items: OrderItemInput[],
|
||||
totals: { subtotalCents: number; discountCents: number; taxCents: number; totalCents: number },
|
||||
): Promise<OrderView> {
|
||||
const existing = await this.repo.findById(id);
|
||||
if (!existing) throw new OrderNotFoundError();
|
||||
if (!this.repo.replaceItems) throw new Error('Order repository does not support item editing');
|
||||
const updated = await this.repo.replaceItems(id, items, totals);
|
||||
if (!updated) throw new OrderNotFoundError();
|
||||
return updated;
|
||||
}
|
||||
|
||||
async transition(id: string, next: OrderState, userId: string): Promise<OrderView> {
|
||||
const existing = await this.repo.findByIdAndUserId(id, userId);
|
||||
if (!existing) throw new OrderNotFoundError();
|
||||
@@ -60,12 +74,12 @@ export class OrderService implements OrderServicePort {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
async transitionAdmin(id: string, next: OrderState): Promise<OrderView> {
|
||||
async transitionAdmin(id: string, next: OrderState, trackingNumber?: string): Promise<OrderView> {
|
||||
const existing = await this.repo.findById(id);
|
||||
if (!existing) throw new OrderNotFoundError();
|
||||
if (!isTransitionAllowed(existing.state, next))
|
||||
throw new OrderStateTransitionError(existing.state, next);
|
||||
const updated = await this.repo.updateState(id, next);
|
||||
const updated = await this.repo.updateState(id, next, trackingNumber);
|
||||
if (!updated) throw new OrderNotFoundError();
|
||||
if (next === 'PAID')
|
||||
await this.events.emit({ type: 'OrderPaid', orderId: id, userId: existing.userId });
|
||||
|
||||
Reference in New Issue
Block a user