This commit is contained in:
2025-12-07 16:05:56 +03:30
parent 041d28fe5d
commit b7452d793d
3 changed files with 46 additions and 5 deletions
+28 -1
View File
@@ -287,7 +287,10 @@ export class OrdersService {
if (!order) {
throw new NotFoundException('Order not found');
}
order.status = OrderStatus.Confirmed;
if (order.status !== OrderStatus.Confirmed) {
throw new BadRequestException('Order must be confirmed before preparing');
}
order.status = OrderStatus.Preparing;
await this.em.persistAndFlush(order);
return order;
}
@@ -344,6 +347,30 @@ export class OrdersService {
return order;
}
async markAsDelivered(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
const readyStatuses = [
OrderStatus.ReadyForCustomerPickup,
OrderStatus.ReadyForDineIn,
OrderStatus.ReadyForDeliveryCar,
OrderStatus.ReadyForDeliveryCourier,
];
if (!readyStatuses.includes(order.status)) {
throw new BadRequestException(
`Order must be in a ready status to mark as delivered. Current status: ${order.status}`,
);
}
order.status = OrderStatus.Delivered;
await this.em.persistAndFlush(order);
return order;
}
/**
* Cleanup job to handle abandoned orders (pending payment for >30 minutes)
* Runs every 10 minutes to check for abandoned orders