order
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user