This commit is contained in:
2025-12-06 10:01:04 +03:30
parent 83829856ad
commit 63ab227290
5 changed files with 94 additions and 20 deletions
+48 -4
View File
@@ -250,9 +250,53 @@ export class OrdersService {
return `This action returns a #${id} order`;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
update(id: number, _updateOrderDto: unknown) {
return `This action updates a #${id} order`;
async acceptOrder(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
if (!order) {
throw new NotFoundException('Order not found');
}
order.status = OrderStatus.Confirmed;
await this.em.persistAndFlush(order);
return order;
}
async rejectOrder(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
if (!order) {
throw new NotFoundException('Order not found');
}
order.status = OrderStatus.RejectedByRestaurant;
await this.em.persistAndFlush(order);
return order;
}
async readyForDelivery(orderId: string) {
const order = await this.em.findOne(Order, { id: orderId });
if (!order) {
throw new NotFoundException('Order not found');
}
let orderStatus: OrderStatus | undefined;
switch (order.deliveryMethod.method) {
case DeliveryMethodEnum.DeliveryCourier:
orderStatus = OrderStatus.ReadyForDeliveryCourier;
break;
case DeliveryMethodEnum.DeliveryCar:
orderStatus = OrderStatus.ReadyForDeliveryCar;
break;
case DeliveryMethodEnum.DineIn:
orderStatus = OrderStatus.ReadyForDineIn;
break;
case DeliveryMethodEnum.CustomerPickup:
orderStatus = OrderStatus.ReadyForCustomerPickup;
break;
default:
throw new BadRequestException('Invalid delivery method');
}
order.status = orderStatus;
await this.em.persistAndFlush(order);
return order;
}
remove(id: number) {
@@ -307,7 +351,7 @@ export class OrdersService {
}
// Update order status to Cancelled
order.status = OrderStatus.Cancelled;
order.status = OrderStatus.CancelledBySystem;
em.persist(order);
await em.flush();